Download presentation
Presentation is loading. Please wait.
1
Converting from Base b to Base c
Start with base b representation Initialize base c value x to 0 Get next xi Going from left to right x m-1…x1x0 Repeat for All digits Convert (xi)b number (Di)c by using table Initialize base c value x to 0 Update the base c value by x=xb+Di
2
Review
3
Fixed Point Numbers
4
CS501 Advanced Computer Architecture
Lecture 34 Dr.Noor Muhammad Sheikh
5
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
6
Converting from calculator’s Base c to Base b
Start with bace c integer Initialize i=0 and v=x Set Di=v mod b And v=v/b Convert (Di )cto (xi )b Set i=i+1 If v!=0, repeat
7
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
8
Converting a Base b fraction to calculator’s Base c
Start with base b representation Convert to Base c number (Di)c by using table Initialize f=0.0 and Set i = -m f-1f-2…f-m xn-1xn-2…x1x0.x-1x-2…x-m Repeat for all digits until i=0 Here the digits are treated from right to left, with division implemented at each step Update f=(f+D)/b And i=i+1
9
Example: Convert (.4cd)16 to Base 10
Solution: F=0 F=(0+13)/16=0.8125 F=( )/16= F=( )/16=( )10
10
Converting a fraction from calculator’s Base c to Base b
Start with fraction f in Base c Initialize i=1 and v=f Set D-i=bv and v=bv - Di Convert Di to f-i Set i=i+1 If v!=0 repeat Until enough digits are generated No division is required and the process should be terminated when enough digits are generated
11
Representation of Negative Numbers
12
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 =( )2
13
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
14
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
15
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
16
Complement representation of negative numbers
Diminished Radix Complement Radix Complement Number Representation 0 or bm - 1 0<x<bm/2 x -bm/2<=x<0 |x|c=(bm-|x| -bm/2+1<=x<0 |x’|c=bm-1-|x|
17
Example Base 2 Complement representation
8 bit 2’s complement 8 bit 1’s complement Number Representation 0 or 255 0<x<128 x -128<=x<0 256-|x| -127<=x<0 255 -|x|
18
Examples of number representations
Decimal 2’s complement 1’s Sign- magnitude 16’s Unsigned 27 011011 1B 11011 .17 0.2B -26 100110 100101 111010 E6 - -0.57 F.6E
19
Example: Multiplication and division using shift operation
Overflow would occur if we use four bits here 6x4 001102x410=110002=2410 60/16 /1610= =310 The fractional portion of the result is lost
20
Example: Multiplication and division of negative numbers
-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
21
Example: Multiplication and division of negative numbers
-24=(101000)2 -24x2=(010100)2=20 -24x2=(110100)2 = -12 Changing the size of the number, 24= (n=6) to (n=8) -24= (n=6) to (n=8)
22
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
23
ALSU
24
Example: unsigned addition in Base 2 and 16
Base 16 addition Base 2 addition A B 4 216 + 3 1 C 116 0 1 0 D D 0 316 00011
25
Addition Hardware Base b unsigned digit adder
(xj+yj+cj)/b (xj+yj+cj)mod b xj yj 0<=cj+1<=1 0<=cj<=1 0<=sj<=b
26
1-bit half adder
27
1-bit full adder
28
Addition Hardware Base b unsigned m-digit adder
x0 y0 co so x1 y1 s1 xm-1 ym-1 Cm-1 sm-1 c1 Cm … c2 The hardware can be implemented using two levels of AND/OR logic
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.