Lecture34
Lecture34
Lecture34
to Base c
Get next xi
Start with base b Initialize base c
Going from
representation value x to 0
left to right
x m-1…x1x0
Convert (xi)b
Repeat for
number (Di)c
All digits
by using table
1
Review
2
Fixed Point Numbers
3
CS501
Advanced Computer
Architecture
Lecture 34
5
Converting from calculator’s
Base c to Base b
Set i=i+1
If v!=0, repeat
6
Example: convert 39010 to base 16
c=10, b=16
Solution:
According to the above algorithm
390/16 =24( rem=6), x0=6
24/16= 1(rem=8), x1=8, x2=1
Thus 39010=18616
7
Converting a Base b fraction to
calculator’s Base c
Convert to Base c
Start with base b Initialize f=0.0 and number (Di)c
representation Set i = -m by using table
f-1f-2…f-m
Repeat for
xn-1xn-2…x1x0.x-1x-2…x-m all digits
until i=0
at each step
8
Example: Convert (.4cd)16 to Base 10
Solution:
F=0
F=(0+13)/16=0.8125
F=(0.8125+12)/16=0.80078125
F=(0.80078125+4)/16=(0.3000488)10
9
Converting a fraction from calculator’s
Base c to Base b
No division is required
and the process should be Set i=i+1
terminated when enough If v!=0 repeat
Until enough digits
digits are generated are generated
10
Representation of Negative
Numbers
11
Example: Convert 0.2410 to base 2
Solution:
0.24*2=0.48, f-1=0
0.48*2=0.96, f-2=0
0.96*2=1.92, f-3=1
0.92*2=1.84, f-4=1
0.84*2=1.68, f-5=1,…
Thus 0.2410=(0.00111)2
12
Sign-magnitude form
15
Complement representation of
negative numbers
Diminished
Radix Complement Radix Complement
Number Representation Number Representation
0 0 0 0 or bm - 1
0<x<bm/2 x 0<x<bm/2 x
16
Example
Base 2 Complement representation
0<x<128 x 0<x<128 x
17
Examples of number representations
18
Example: Multiplication and division
using shift operation
Overflow would occur if
• 6x4 we use four bits here
001102x410=110002=2410
• 60/16
01111002/1610=00000112=310
The fractional
portion of the
result is lost
19
Example: Multiplication and division
of negative numbers
• -6x4
-6=(11010)2
-6x4=(01000)2=8 which is wrong!
using less no. of bits might change sign
So, -6=(111010)2
-6x4=(101000)2 = -24
20
Example: Multiplication and division
of negative numbers
• -24x2
-24=(101000)2
-24x2=(010100)2=20
-24x2=(110100)2 = -12
Changing the size of the number,
24=011000 (n=6) to 00011000 (n=8)
-24=101000 (n=6) to 11101000 (n=8)
21
Unsigned addition operation
The digitwise procedure for adding m-digit
base b numbers x and y is as shown
Increment j=j+1
Repeat if j<m
22
ALSU
23
Example: unsigned
addition in Base 2 and 16
0<=cj+1<=1
(xj+yj+cj)/b
0<=cj<=1
(xj+yj+cj)mod b
0<=sj<=b
25
1-bit half adder
26
1-bit full adder
27
Addition Hardware
Base b unsigned m-digit adder
xm-1 ym-1 x1 y1 x0 y0
Cm Cm-1 c2 c1
… co
sm-1 s1 so