Professional Documents
Culture Documents
kULIAH 5
kULIAH 5
Number Representation
Unsigned Integers
• From chapter 1.
B bn 1bn 2 ...b1b0
n 1 n2
V ( B) bn 1 2 bn 2 2 ... b1 2 b0 2
1 0
n 1
bi 2i
i 0
Unsigned Integers
• Hexadecimal and
Octal Numbers
K kn 1kn 2 ...k1k0
n 1
V ( K ) ki r i
i 0
• In General
V ( K ) ki r i
i
Examples
• What is decimal value of
110.012
1 22 1 21 0 20 0 21 1 22 4 2 0.25 6.2510
177.48
1 82 7 81 7 80 4 81 64 56 7 0.5 127.510
1F16
• Binary Hex
110.1012 = 0110.10102 = 6.A16
1 hexa digit = 4 binary digit
• Octal Hex 0…F = 0000,…,1111
• Divide repeatedly by r:
Quotient Q0 = D/r = k3 r2 + k2 r + k1 remainder = k0
Quotient Q1 = Q0/r = k3 r + k2 remainder = k1
Quotient Q2 = Q1/r = k3 remainder = k2
Quotient Q3 = Q2/r = 0 remainder = k3
Carry Sum
1100 1 1 1x 1y c s
+1101 + 0 0 00 10 0 0
0 1 0 1
------------- -------------
1 0 0 1
1 1 1 0
Half Adder
+y +0 +1 +0 +1
c s 0 0 0 1 0 1 1 0
Carry Sum
Carry Sum
x y c s
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 0
x
s
y
x s
HA
y c
c
0 1 1 yi si
1 1 1 ci
si = xi yi ci
xi yi
ci 00 01 11 10
ci + 1
0 1
1 1 1 1
ci + 1 = xi yi + xi ci + yi ci
Ripple Adder
• Adding n-bit numbers
• Carry signals “ripple” through from LSB to
MSB
x n –1 yn – 1 x1 y1 x0 y0
c1
cn FA cn ” 1 c2 FA FA c0
sn – 1 s1 s0
Magnitude
MSB
b n – 1 b n – 2 b 1 b 0
Magnitude
Sign
0 denotes +
1 denotes – MSB
n
N = (2 - 1) - N 2 4 = 10000
-1 = 00001
Example: 1's complement of 7
1111
-7 = 0111
-5
1011 0101
+5 • Generation of the 2’s
-6
1010 0110 complement as 2r - N
1001
1000
0111 +6 implies r + 1 bits available in
-7
-8
+7 system
Twos Complement Operations
Example: Twos complement of 7 24 = 10000
sub 7 = 0111
1001 = repr. of -7
sub -7 = 1001
0111 = repr. of 7
Shortcut method:
Twos complement = bitwise complement + 1
N* = 2r - N
0111 -> 1000 + 1 -> 1001 (representation of -7)
ignore ignore
Overflow in 2’s comp
• Overflow: result doesn’t fit in range of numbers
• Examples (5 bit)
( + 15) 01111 (–15) 10001
+ ( + 2) + 00010 + (+ 2 ) + 00010
( -15) 10001 (–13 ) 10011
Examples
• Add these 4-bit 2’s comp numbers. Does overflow
occur?
( + 7) 0111 ( –7) 1001
+ ( + 2) + 0010 + ( + 2) + 0010
( + 9) 1001 ( –5) 1011
c4 = 0 c4 = 0
c3 = 1 c3 = 0
y y y
n–1 1 0
Add Sub
control
x x x
n–1 1 0
c n-bit adder c
0
n
sn–1 s1 s0
Fast Adders
• Ripple adder is slow (NDt for N bits)
– The carry bits must propagate from one full adder
to the next
xn –1 yn – 1 x1 y1 x0 y0
c1
cn FA cn ” 1 c2 FA FA c0
sn – 1 s1 s0
MSB position LSB position
adder
si = xi xor yi xor ci (sum) c i+1 FA ci
• Then 1 OR gate
ci+1 = gi + pi ci 2 AND, 2 OR
1 AND 1 AND
1 OR
gate gate
gate
Fast Adder Equations
(continued)
• Express ci in terms of x’s, y’s, and ci-1
ci+1 = gi + pi ci
= gi + pi (gi-1 + pi-1 ci-1 )
= gi + pi gi-1 + pi pi-1 ci-1
Carry-
Lookahead
x0 y0
Adder
g1 p1 g0 p0
c0
c2
c1
s1 s0
3-bit Fast Adder
• We have
• Note that
s0 = x0 $ y0 $ c0
– The p’s and g’s take one
c1 = g0 + p0 c0 gate delay
s1 = x1 $ y1 $ c1 – Each carry is produced
c2 = g1 + p1 g0 + p1 p0 c0 by a two-level AND-OR
• Find !! circuit (two additional
s2 = x2 $ y2 $ c2 gate delays)
c3 = g2 + p2 c2 – The sum bits take
another gate delay
= g2 + p2 (g1 + p1 g0 + p1 p0 c0 )
=> total is 4 gate delays
= g2 + p2 g1 + p2 p1 g0 + p2 p1 p0 c0
Note: $ = XOR
• In general
ci+1 = gi + pi gi-1 + pi pi-1 gi-2 + … + pi pi-1 ··· p2 p1 g0 + pi pi-1 ···
p1 p0 c0
Combination CLA-RCA
c8
c32 Block c24 c16 Block Block c0
3 1 0
s31– 24 s15– 8 s7 – 0
Hierarchical CLA Adder
x31– 24 y31– 24 x15– 8 y15– 8 x7 – 0 y7 – 0
G3 P3 G1 P1 G0 P0
s31– 24 s15– 8 s7 – 0
c32 c16 c8
Second-level lookahead
Floating Point Number
32 bits
S E M
Sign
0 denotes+ 8-bit 23 bits of mantissa
1 denotes– excess-127
exponent
(a) Single precision
64 bits
S E M
Sign
11-bit excess-1023 52 bits of mantissa
exponent
(c) Double precision
Binary Coded Decimal
Addition of BCD digits
X 0111 7
+ Y + 0101 + 5
Z 1100 12
+ 0110
carry 10010
S=2
X 1000 8
+ Y + 1001 + 9
Z 10001 17
+ 0110
carry 10111
S=7