0% found this document useful (0 votes)
3 views28 pages

Lecture34

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1/ 28

Converting from Base b

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

Update the base c


Initialize base c value by
value x to 0 x=xb+Di

1
Review

2
Fixed Point Numbers

3
CS501
Advanced Computer
Architecture

Lecture 34

Dr.Noor Muhammad Sheikh


4
Example: Convert the Hexadecimal
number B316 to base
10
Solution:
According to the above algorithm,
X=0
X=x+B(=11)=11
X=16*11+3= 179
Hence B316=17910

5
Converting from calculator’s
Base c to Base b

Set Di=v mod b


Start with bace c Initialize i=0
And v=v/b 
integer and v=x
Convert (Di )cto (xi )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

Here the digits are


treated from right to left, Update f=(f+D)/b
with division implemented And i=i+1

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

Start with fraction Set D-i=bv 


Initialize i=1 and v=bv - Di
f in Base c
and v=f
Convert Di to f-i

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

• This is the simplest form for


representing a signed number
• A symbol representing the sign of the
number is appended to the left of the
number
• This representation complicates the
arithmetic operations
13
Radix Complement
• This is the most common
representation
• Given an m-digit base b number x,
the radix complement of x is
xc= ( bm – x) mod bm
• This representation makes the
arithmetic operations much easier
14
Diminished Radix Complement
• The diminished radix complement of an m-digit
number x is
xc’=bm-1-x
• This complement is easier to compute than the
radix complement
• The two complement operations are
interconvertible, as
xc= ( xc’+1)mod bm

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

-bm/2<=x<0 |x|c=(bm-|x| -bm/2+1<=x<0 |x’|c=bm-1-|x|

16
Example
Base 2 Complement representation

8 bit 2’s complement 8 bit 1’s complement


Number Representation Number Representation
0 0 0 0 or 255

0<x<128 x 0<x<128 x

-128<=x<0 256-|x| -127<=x<0 255 -|x|

17
Examples of number representations

Decimal 2’s 1’s Sign- 16’s Unsigned


complement complement magnitude complement
27 011011 011011 011011 1B 11011

.17 0.00101011 0.00101011 0.00101011 0.2B 0.00101011

-26 100110 100101 111010 E6 -

-0.57 1.01101110 1.01101101 1.100100 F.6E -


10

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

Initialize digit j=0 and c-in c0=0

Compute j sum sj=(xj+yj+cj)mod b


And carry cj+1=(xj+yj+cj)/b

Increment j=j+1
Repeat if j<m
22
ALSU

23
Example: unsigned
addition in Base 2 and 16

Base 16 addition Base 2 addition


A B 4 216 1000112
+ 3 1 C 116 + 0110112
0 10 00011
D D 0 316 1111102
24
Addition Hardware
Base b unsigned digit adder
xj yj

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

The hardware can be implemented


using two levels of AND/OR logic 28

You might also like