Coa Chapter-2
Coa Chapter-2
By ahmed s.
1
Data Types
Data type is the binary information which 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 can be
• Numbers used in arithmetic computations
• Letters of the alphabet used in data processing
• Other discrete symbols used for specific purpose
– Number Systems
• Base or Radix r system : uses distinct symbols for r digits
• The 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 the sum
of all weighted digits
2
Contd…
Decimal System/Base-10 System:
Composed of 10 symbols or numerals(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
Binary System/Base-2 System:
Composed of 2 symbols or numerals(0, 1)
Bit = Binary digit
Hexadecimal System/Base-16 System :
Composed of 16 symbols or numerals(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B,
C, D, E, F)
Octal System/Base-8 System :
Composed of 8 symbols or numerals(0, 1, 2, 3, 4, 5, 6, 7)
3
Conversions
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
Repeated division by two for non-fraction number until zero
37 / 2 = 18 remainder 1 (binary number will end with 1) : LSB
18 / 2 = 9 remainder 0
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 3710 = 1001012
4
Contd…
Repeated multiplication by two for fraction number until
zero or until the required significant figure.
• 0.375 x 2 = 0.750 integer 0 MSB
• 0.750 x 2 = 1.500 integer 1 .
• 0.500 x 2 = 1.000 integer 1 LSB
Read the result downward .37510 = .0112
5
Table 2-1
Hex Binary
Hex-to-Decimal Conversion Decimal
0 0000 0
2AF16 = (2 x 16 ) + (10 x 16 ) + (15 x 16 )
2 1 o 1
2
0001
0010
1
2
3 0011 3
= 51210 + 16010 + 1510 4 0100 4
5 0101 5
= 68710 6 0110 6
7 0111 7
Decimal-to-Hex Conversion 8 1000 8
9 1001 9
42310 / 16 = 26 remainder 7 (Hex number will end with 7) : LSB A
B
1010
1011
10
11
2610 / 16 = 1 remainder 10 C
D
1100
1101
12
13
110 / 16 = 0 remainder 1 (Hex number will start with 1) : MSB E 1110 14
F 1111 15
Read the result upward to give an answer of 42310 = 1A716
6
Binary-Coded-Decimal Code
Each digit of a decimal number is represented by its binary equivalent
8 7 4 (Decimal)
7
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
(r-1)’s Complement
(r-1)’s Complement of N = (r -1)-N, where
n
N : given number
r : base
n : digit number
• 9’s complement of N=546700
(106-1)-546700= (1000000-1)-546700= 999999-546700
= 453299
• 1’s complement of N=101101
(26-1)-101101= (1000000-1)-101101= 111111-101101 8
Contd…
r’s Complement
– r’s Complement of N = rn-N
• 10’s complement of 2389= 7610+1= 7611
• 2’s complement of 1101100= 0010011+1= 0010100
* r’s Complement
(r-1)’s Complement +1 =(rn-1)-N+1= rn-N
9
Subtraction of Unsigned Numbers (M-N), N0
• 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)
MN M N 13250(M) - 72532(N) = -59282
72532(M) - 13250(N) = 59282 13250
Discard 72532 + 27468 (10’s complement of 72532)
End Carry 0 40718
+ 86750 (10’s complementNoof
End13250)
Carry
Result = -(10’s complement of 40718)
1 59282 = -(59281+1) = -59282
Result = 59282
X Y 1000011(X) - 1010100(Y) = -0010001
1000011
XY
Binary Example) + 0101100 (2’s complement of 1010100)
0 1101111
1010100(X) - 1000011(Y) = 0010001
Result = -(2’s complement of 1101111)
1010100 = -(0010000+1) = -0010001
+ 0111101 (2’s complement of 1000011)
1 0010001
*Numeric Data
1) Fixed Point
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
0 0001110 1 1110010
• Signed-magnitude representation
• Signed-1’s complement representation
• Signed-2’s complement representation
Arithmetic Addition
Addition Rules of Ordinary Arithmetic
The signs are same : sign= common sign, result= add
Example: (-12) + (-13) = -25
(+12) + (+13) = +25
The signs are different : sign= larger sign, result= larger-smaller
Example : (+25) + (-37)
= 37 - 25 = -12
Addition Rules of the signed 2’s complement
Add the two numbers including their sign bits
Discard any carry out of the sign bit position
*Addition Example)
+ 6 00000110 - 6 11111010
+ 13 00001101 + 13 00001101
+ 19 00010011 + 7 00000111
+ 6 00000110 - 6 11111010
- 13 11110011 - 13 11110011
- 7 11111001 - 19 11101101
12
Arithmetic Subtraction
Subtraction is changed to an Addition
(± A) - (+ B) = (± A) + (- B)
(± A) - ( - B) = (± A) + (+ B)
Subtraction Example (- 6) - ( - 13) = +7
11111010 - 11110011 = 11111010 + 2’s comp of 11110011
= 11111010 + 00001101
= 1 00000111 = +7
Discard End Carry
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 Flip flop is13
Contd…
• 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
the MSB always represents the sign
- the sign bit is treated as part of the number
- the end carry does not indicate an overflow
Overflow Example
out in out in
carries 0 1 carries 1 0
+ 70 0 1000110 - 70 1 0111010
+ 80 0 1010000 - 80 1 0110000 14
Decimal Fixed-Point Representation
• A 4 bit decimal code requires four F/Fs for each decimal
digit. Its Advantage is Computer I/O data are generated by
people who use the decimal system
• The representation of 4385 in BCD requires 16 F/Fs (0100
0011 1000 0101).
• The representation in decimal is wasting a considerable
amount of storage space and the circuits required to
perform decimal arithmetic are more complex.
*Decimal Example (+375) + (-240)
375 + (10’s comp of 240)= 375 + 760
16
Other Binary Codes
Gray Code
The important feature of the Gray code is that it exhibits only a single bit
change from one code word to the next in sequence.
The data must be converted into digital form before they can be used by
a digital computer(Analog to Digital Converter)
The analog data are represented by the continuous change of a shaft
position(Rotary Encoder of Motor)
The rules to convert a binary number to a Gray code:
1. The most significant bit (left-most) in the Gray code is the
same as the corresponding MSB in the binary number.
2. Going from left to right, add each adjacent pair of binary
code bits to get the next Gray code bit. Discard carries.
17
Contd…
Example: Convert the binary number 11000110 to Gray code.
Solution:
18
EXCESS-3 CODE
Is a digital code related to BCD that is derived by adding 3 to each
decimal digit and then converting the result of that addition to 4-bit
binary.
20
Contd…
Table for Four Different Binary Codes for the Decimal Digits.
21
Quiz- 1 5%
1) convert the binary number 11110011
to its equivalent gray code.
2) Compare and contrast combinational
and sequential circuit.
22