0% found this document useful (0 votes)
13 views23 pages

COA Chapter 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views23 pages

COA Chapter 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Chapter Three

Number Systems and Data


Representation

1
3.1 Data Types
 Binary information is stored in memory or processor registers
 Registers contain either data or control information
 Data are numbers and other binary-coded information
 Control information is a bit or a group of bits used to specify the
sequence of command signals
 Data types found in the registers of digital computers
 Numbers used in arithmetic computations
 Letters of the alphabet used in data processing
 Other discrete symbols used for specific purpose
» Number Letter) gray code, error detection code, …
 Number Systems
 Base or Radix r system : uses distinct symbols for r digits
 Most common number system :Decimal, Binary, Octal, Hexadecimal
 Positional-value(weight) System : r2 r 1r0.r-1 r-2 r-3
» Multiply each digit by an integer power of r and then form he sum of all
weighted digits

2
 Decimal System/Base-10 System
 Composed of 10 symbols or numerals(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0)
 Binary System/Base-2 System
 Composed of 10 symbols or numerals(0, 1)
 Bit = Binary digit
 Hexadecimal System/Base-16 System : Tab. 3-2
 Composed of 16 symbols or numerals(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F)
 Binary-to-Decimal Conversions
1011.1012 = (1 x 23) + (0 x 22)+ (1 x 21) + (1 x 2o) + (1 x 2-1) + (0 x 2-2) + (1 x 2-3)
= 810+ 0 + 210 + 110 + 0.510 + 0 + 0.12510
= 11.62510
 Decimal-to-Binary Conversions Decimal point conversion
Repeated division 0.375 x 2 = 0.750 integer 0 MSB
37 / 2 = 18 remainder 1 (binary number will end with 1) : LSB 0.750 x 2 = 1.500 integer 1 .
18 / 2 = 9 remainder 0 0.500 x 2 = 1.000 integer 1 LSB
Read the result downward .37510 = .0112
9 / 2 = 4 remainder 1
4 / 2 = 2 remainder 0
2 / 2 = 1 remainder 0
1 / 2 = 0 remainder 1 (binary number will start with 1) : MSB
Read the result upward to give an answer of 37 10 = 1001012

3
 Hex-to-Decimal Conversion Table 3-2
Hex Binary Decimal
2 1 o 0 0000 0
2AF16 = (2 x 16 ) + (10 x 16 ) + (15 x 16 ) 1 0001 1
= 51210 + 16010 + 1510 2 0010 2
3 0011 3
= 68710 4 0100 4
5 0101 5
 Decimal-to-Hex Conversion 6
7
0110
0111
6
7
42310 / 16 = 26 remainder 7 (Hex number will end with 7) : LSB 8 1000 8
9 1001 9
2610 / 16 = 1 remainder 10 A 1010 10
B 1011 11
110 / 16 = 0 remainder 1 (Hex number will start with 1) : MSB C 1100 12
D 1101 13
Read the result upward to give an answer of 42310 = 1A716 E 1110 14
F 1111 15

 Hex-to-Binary Conversion  Binary-to-Hex Conversion


9F216 = 9 F 2 1 1 1 0 1 0 0 1 1 02 = 0 0 1 1 1 0 1 0 0 1 1 0

= 1001 1111 0010 3 A 6


= 1001111100102 = 3A616

4
 Binary-Coded-Decimal Code
 Each digit of a decimal number is represented by its binary equivalent
8 7 4 (Decimal)

1000 0111 0100 (BCD)


 Only the four bit binary numbers from 0000 through 1001 are used
 Comparison of BCD and Binary
13710 = 100010012 (Binary) - require only 8 bits
13710 = 0001 0011 0111BCD (BCD) - require 12 bits
 Alphanumeric Representation
 Alphanumeric character set
» 10 decimal digits, 26 letters, special character($, +, =,….)
» A complete list of ASCII : (Find in Google: or https://www.ascii-code.com/)
 ASCII(American Standard Code for Information Interchange)
» Standard alphanumeric binary code uses seven bits to code 128
characters, but extended ASCII use 8-bit and code 256 characters.

5
 3.2 Complements
 Complements are used in digital computers for simplifying the
subtraction operation and for logical manipulation
 There are two types of complements for base r system
 1) r’s complement 2) (r-1)’s complement
» Binary number : 2’s or 1’s complement
» Decimal number : 10’s or 9’s complement
N : given number
 (r-1)’s Complement r : base
 (r-1)’s Complement of N = (rn-1)-N n : digit number
» 9’s complement of N=546700
(106-1)-546700= (1000000-1)-546700= 999999-546700
= 453299 546700(N) + 453299(9’s com)
» 1’s complement of N=101101 =999999
(26-1)-101101= (1000000-1)-101101= 111111-101101
= 010010 101101(N) + 010010(1’s com)
=111111
 r’s Complement
 r’s Complement of N = rn-N * r’s Complement
(r-1)’s Complement +1 =(rn-1)-N+1= rn-N
» 10’s complement of 2389= 7610+1= 7611
» 2’s complement of 1101100= 0010011+1= 0010100
6
 Subtraction of Unsigned Numbers (M-N), N0
 1) M + (rn-N)
 2) M  N : Discard end carry, Result = M-N
 3) M  N : No end carry, Result = - r’s complement of (N-M)

» Decimal Example)
M  N 72532(M) - 13250(N) = 59282 MN 13250(M) - 72532(N) = -59282
72532 13250
Discard + 86750 (10’s complement of 13250) + 27468 (10’s complement of 72532)
End Carry 1 59282 0 40718
No End Carry
Result = 59282 Result = -(10’s complement of 40718)
= -(59281+1) = -59282
» Binary Example)
X  Y 1010100(X) - 1000011(Y) = 0010001 XY 1000011(X) - 1010100(Y) = -0010001
1010100 1000011
+ 0111101 (2’s complement of 1000011) + 0101100 (2’s complement of 1010100)
1 0010001 0 1101111
Result = 0010001 Result = -(2’s complement of 1101111)
= -(0010000+1) = -0010001

7
*Numeric Data
1) Fixed Point
 3.3 Fixed-Point Representation 2) Floating Point
 Computers must represent everything with 1’s and 0’s, including the
sign of a number and fixed/floating point number
* 32.25
 Binary/Decimal Point 1) 0.25, 2) 32.0, 3) 32.25
 The position of the binary/decimal point is needed to represent fractions,
integers, or mixed integer-fraction number
 Two ways of specifying the position of the binary point in a register
 1) Fixed Point : the binary point is always fixed in one position
» A binary point in the extreme left of the register(Fraction : 0.xxxxx)
» A binary point in the extreme right of the register(Integer : xxxxx.0)
 The binary point is not actually present, but the number stored in the register is treated
as a fraction or as an integer
 2) Floating Point : the second register is used to designate the position of the
binary point in the first register
* MSB for Sign
 Integer Representation +14 -14 “0” is plus +
“1” is minus -
 Signed-magnitude representation 0 0001110 1 0001110
Most
Common  Signed-1’s complement representation 0 0001110 1 1110001
 Signed-2’s complement representation
0 0001110 1 1110010
8
 Arithmetic Addition (-12) + (-13) = -25
 Addition Rules of Ordinary Arithmetic
(+12) + (+13) = +25
» The signs are same : sign= common sign, result= add (+25) + (-37)
» The signs are different : sign= larger sign, result= larger-smaller = 37 - 25 = -12

 Addition Rules of the signed 2’s complement *Addition Example)


» Add the two numbers including their sign bits + 6 00000110 - 6 11111010
» Discard any carry out of the sign bit position + 13 00001101 + 13 00001101
+ 19 00010011 + 7 00000111
 Arithmetic Subtraction
 Subtraction is changed to an Addition + 6 00000110 - 6 11111010
- 13 11110011 - 13 11110011
» (± A) - (+ B) = (± A) + (- B)
- 7 11111001 - 19 11101101
» (± A) - ( - B) = (± A) + (+ B)
* Subtraction Example) (- 6) - ( - 13) = +7
11111010 - 11110011 = 11111010 + 2’s comp of 11110011
Discard = 11111010 + 00001101
End Carry = 1 00000111 = +7

 Overflow
 Two numbers of n digits each are added and the sum occupies n+1 digits
 n + 1 bit cannot be accommodated in a register with a standard length of n
bits(many computer detect the occurrence of an overflow, and a
corresponding F/F is set) 9
 Overflow
 An overflow may occur if the two numbers added are both positive or both
negative
» When two unsigned numbers are added
 an overflow is detected from the end carry out of the MSB position
» When two signed numbers are added * Overflow Example)
 the MSB always represents the sign
out in out in
carries 0 1 carries 1 0
- the sign bit is treated as part of the number
+ 70 0 1000110 - 70 1 0111010
- the end carry does not indicate an overflow
+ 80 0 1010000 - 80 1 0110000
 Overflow Detection + 150 1 0010110 - 150 0 1101010
 Detected by observing the carry into the sign bit position and the carry out
of the sign bit position
 If these two carries are not equal, an overflow *Decimal Exam) (+375) + (-240)
condition is produced 375 + (10’s comp of 240)= 375 + 760

 Decimal Fixed-Point Representation 0 375 (0000 0011 0111 0101)


 A 4 bit decimal code requires four F/Fs +9 760 (1001 0111 0110 0000)
* Advantage * 0 135 (0000 0001 0011 0101)
for each decimal digit
Computer I/O
data are generated  The representation of 4385 in BCD requires 16 F/Fs (0100 0011 1000 0101)
by people who use
 The representation in decimal is wasting a considerable amount of storage
the decimal
system space and the circuits required to perform decimal arithmetic are more
complex 10
3.4 Floating-Point Representation
 The floating-point representation of a number has two parts
 1) Mantissa : signed, fixed-point number
 2) Exponent : position of binary(decimal) point
* Decimal + 6132.789
 Scientific notation : m x re (+0.6132789 x 10+4) Fraction Exponent
+0.6132789 +4
 m : mantissa, r : radix, e : exponent
 Example : m x 2e = +(.1001110)2 x 2+4 Fraction Exponent
01001110 000100
 Normalization
 Most significant digit of mantissa is nonzero
 N.B In this representation decimal numbers are represented with a
fixed length format. In order not to waste bits, the representation will
normalize all the numbers.
 For example, 0.000123 wastes three zeroes on the left before non -
zero digits. There zeroes have no meaning except to indicate the
position of the Decimal point.
 Normalizing this number result in .123x10-3 .123 is the normalized
mantissa; -3 is the exponent. We have normalized this by eliminating all
the meaningless zeroes to the left of the first non-zero digit and by
adjusting the exponent. 11
IEEE Floating Point
 IEEE Standard 754
 Supported by all major CPUs
 The IEEE standards committee consisted mostly of hardware
people, plus a few academics led by W. Kahan at Berkeley.
 Main goals:
 Consistent representation of floating point numbers by all
machines .
 Correctly rounded floating point operations.
 Consistent treatment of exceptional situations such as division
by zero.
 Example 1: 22.1 is normalized as .221x102.
 The general form of floating point representation is Mx10E where M
is the mantissa, and E is the exponent.
 It can be seen that a normalized number is characterized by a
mantissa less than 1 and greater than or equal to 1, all cases when
the number is not zero.
12
 Example 2: 111.01 is normalized as .11101x23.
 The mantissa is 11101. The exponent is 3.
 The general structure of floating point is:

 In representing a number in floating point we use 1 bit for sing, some


bits for exponent and the remaining bit for mantissa.
 In floating point representation the exponent is represented by a
biased exponent (Characteristic).
 Biased exponent = true exponent + excess 2n-1,
where n is the number of bits representing the
exponent.

13
 Example 1.
 Represent –234.375 in floating point using 7 bit for exponent and 16 bit
for mantissa.
 First we have to change to normalized binary
 i.e 234 = 11100010
 0.375= 0.011 , Then
 234.375 = 11100010.011 = 0.11100010011x2 8
 True exponent = 8
 Excess 2 n-1 = 2 7-1= 26= 64, Finally;
 Biased exponent = 8+26 = 8+64 = 72
= 100 1000 2
 Therefore –234.375 is represented as:

14
 Example 2.
 Represent 34.25 in floating point using 7 bit for
exponent and 24 bits for mantissa.
 34.25 = 1000 10.0 12
 The normalized form of 34.25 = .10001001x 26
 True exponent = 62 n-1 = 2 7-1= 6+26
=6+64=70
 70 = 10001102
 Therefore, 34.25 is represented as

0 1000110 100010010000…..0

15
3.5 Error Detection Codes
 Binary information transmitted through some form of communication
medium is subject to external noise

~
Transmitter Receiver
 Parity Bit
 An extra bit included with a binary message to make the total number of 1’s
either odd or even
 Even-parity method
 The value of the parity bit is chosen so that the total number of 1s (including the
parity bit) is an even number
1 1 0 0 0 0 1 1
Added parity bit
 Odd-parity method
 Exactly the same way except that the total number of 1s is an odd number

1 1 0 0 0 0 0 1
Added parity bit
16
Even/odd parity (1)

 Computers can sometimes make errors when


they transmit data.
 Even/odd parity:
 is basic method for detecting if an odd number of bits
has been switched by accident.
 Odd parity:
 The number of 1-bit must add up to an odd number
 Even parity:
 The number of 1-bit must add up to an even number

17
Even/odd parity (2)

 The computer knows which parity it is using


 If it uses an even parity:
 If the number of of 1-bit add up to an odd number
then it knows there was an error:
 If it uses an odd:
 If the number of of 1-bit add up to an even number
then it knows there was an error:
 However, If an even number of 1-bit is flipped the parity
will still be the same. But an error occurs
 The even/parity can’t this detect this error:

18
Even/odd parity (3)

 It is useful when an odd number of 1-bits is flipped.

 Suppose we have an 7-bit binary word (7-digits).


 If you need to change the parity you need to add 1
(parity bit) to the binary word.
 You now have 8 digit word.
 However, the computer knows that the added bit is a
parity bit and therefore ignore it.

19
Example (1)

 Suppose you receive a binary bit word “0101” and you know you are
using an odd parity.
 Is the binary word errored?
 The answer is yes:
 There are 2 1-bit, which is an even number
 We are using an odd parity
 So there must have an error.

20
Parity Bit
 A single bit is appended to each data chunk
 makes the number of 1 bits even/odd
 Example: even parity
 1000000(1)
 1111101(0)
 1001001(1)
 Example: odd parity
 1000000(0)
 1111101(1)
 1001001(0)

21
Parity Checking

 Assume we are using even parity with 7-bit ASCII.


 The letter V in 7-bit ASCII is encoded as 0110101.
 How will the letter V be transmitted?
 Because there are four 1s (an even number), parity is set to zero.
 This would be transmitted as: 01101010.
 If we are using an odd parity:
 The letter V will be transmitted as 01101011

22
Exercise
 Suppose you are using an odd parity. What should the binary word
“1010” look like after you add the parity bit?
 Answer:
 There is an even number of 1-bits.
 So we need to add another 1-bit
 Our new word will look like “10101”.
 Suppose you are using an even parity. What should the binary word
“1010” look like after you add a parity bit?
 Answer:
 There is an even number of 1’s.
 So we need to add another 0
 Our new word will look like “10100”.

23

You might also like