You are on page 1of 16

Digital Logic Design

EGRE 254
Number Systems and Codes
1/12/09

09/27/22 1
Positional Number Systems
• Numbers are commonly represented in the
base 10 positional number system.
– For example

1492.1066  1492.106610
3 2 1 0
 1  10  4  10  9  10  2  10
 1  101  0  102  6  103  6  104

09/27/22 2
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: d d ...d d .d d d ... d 
p 1 p 2 1 0 1  2  n 1 n r

p 1 p 1
 i  i
   d i  10     ( d i )10  r 
 i  n r  i n 10

di – in base r di – in base 10
09/27/22 3
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 =
09/27/22 4
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.

09/27/22 5
Decimal (10) Binary (2) Octal (8) Hexadecimal (16)
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
09/27/22 15 1111 17 F 6
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

09/27/22 7
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.
D  d p 1...d 2 d1d 0 r
– Fractional number.
D  .d 1d 2 ...d  p r
09/27/22 8
Base 10 to base r (integer case)
D  d p 1  r p 1  ...  d 2  r 2  d1  r  d 0
D p 2 1 d0 R0
 d p 1  r  ...  d 2  r  d1   Q1 
r r r
 d 0  R0
Q1  d p 1  r p 2  ...  d 2  r1  d1
Q1 p 3 d1 R1
 d p 1  r  ...  d 2   Q2 
r r r
 d1  R1
...
09/27/22 9
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
09/27/22 10
In practice
• You may get mixed up
0 R0 on direction to read
16 5 R  510  516 the answer.
16 93 R  1310  D16 • 5D416 or 4D516?
• Note that 5D4 = 0…
16 1492 R  410  416 05D4
• 4D5 not same as
4D50…0

09/27/22 11
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

09/27/22 12
Example
• For a number containing both an integer
and a fractional part. Compute the two parts
separately and combine.
• 1492.632812510 = 5D4.A216

09/27/22 13
Special Case converting between base r and r n
• Convert 132.68 to binary.
– Could convert to decimal and then binary.
– Easier way.
(132.6)8  1  82  3  81  2  6  81
 (0  22  0  21  1)  82  (0  22  1  21  1)  81
 (0  22  1  21  0)  (1  22  1  21  0)  81
 ( 0  28  0  2 7  1  2 6 )  ( 0  2 5  1  2 4  1  2 3 )
 (0  22  1  21  0)  (1  2 1  1  2 2  0  2 3 )
 (001,011,010.110) 2
09/27/22 14
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.
09/27/22 15
09/27/22 16

You might also like