Positional Number Systems: Conversion Techniques and Examples
Learn about converting numbers in different bases, from base 10 to base r, using various techniques and examples. Understand how to convert both integers and fractional numbers efficiently.
Positional Number Systems: Conversion Techniques and Examples
E N D
Presentation Transcript
Digital Logic Design EGRE 254 Number Systems and Codes 1/12/09
Positional Number Systems • Numbers are commonly represented in the base 10 positional number system. • For example
In general (see page 26) • A number D of radix or base r with p digits to the left of the radix point and n digits to the right of the radix point can be expressed as: di – in base 10 di – in base r
Examples • 156.78 = (1x102 + 5x101 + 6x100 + 7x10-1 )8 = (1x82 + 5x81 + 6x80 + 7x8-1 )10 = (64 + 40 + 6 + .875)10 = 110.87510 • 559 = (5x101 + 5x100)9 = (5x91 + 5x90)10 = (45 + 5)10 = 5010 • 1212 = (1x121 + 2x120)10 = (12 + 2)10 = 1410 • 101100.112 =
Examples • Does r10 = 10r? Prove it! • Does rb = br? Prove it! • 111b = 13310 Find b. • (41/3)b = 13b Find b. • (33/3)b = 11b Find b.
Example • (5D4.A2)16 • = (5x102+Dx101+4+Ax10-1+2x10-2)16 = (5x162+13x161+4+10x16-1+2x16-2)10 = (1280+208+4+.625+.0078125)10 = (1492.6328125)10
How do we convert from base 10 to base r? • We could use previous techniques, but we would have to do arithmetic in base r. • Not desirable. • Consider two cases. • Integer number. • Fractional number.
Example – Integer to Hex 1492 = (d3 d2 d1 d0)16 = d3x163+ d2x162+ d1x16+ d0 1492/16 = 93+4/16 = d3x162+ d2x16+ d1+ d0/16 d0 = 4 93 = d3x162+ d2x16+ d1 93/16 = 5 +13/16 = d3x16+ d2+ d1/16 d1 = 1310 = D16 5 = d3x16+ d2 5/16 = 0 + 5/16 = d3 + d2/16, d3 = 0, d2 = 5 149210 = 5D416
In practice • You may get mixed up on direction to read the answer. • 5D416 or 4D516? • Note that 5D4 = 0…05D4 • 4D5 not same as 4D50…0
Example fraction to hex (.6328125)10 = (.d-1 d-2 d-3…)16 = (d-1x16-1+d-2x16-2+d-3x16-3+…)10 How do we find d-1? Multiply by 16. 16 x .6328125 = 10.125 = d-1+d-2x16-1+d-3x16-2+… d-1 = 10 and .125 = d-2x16-1+d-3x16-2+… Multiply by 16. Then,.125 x 16 = 2.00 = d-2+d-3x16-1+… d-2 = 2 and d-n = 0 for n > 2. Therefore, (.6328125)10 = (.A2)16
Example • For a number containing both an integer and a fractional part. Compute the two parts separately and combine. • 1492.632812510 = 5D4.A216
Special Case converting between base r and rn • Convert 132.68 to binary. • Could convert to decimal and then binary. • Easier way.
Examples • Convert (11010.11)2 to octal, and to hexadecimal. (11010.11)2 = (11,010.110)2 = 32.68 (11010.11)2 = (1,1010.1100)2 =1A.C16 • Convert (121.121)3 to base 9 = 32. • Convert (1234.567)8 to hexadecimal. • Hint 8 = 23 and 16 = 24.