Title: Number systems and codes
1Number systems and codes
- Number systems
- Ordered set of symbols or digits, with defined
relations for ? ? ? - Radix (base) r
- Total of symbols allowed in system
- Decimal 10 digits 09 radix 10
- Binary 2 digits 0, 1 radix 2
2Number systems and codes
- Positional notation
- N (an-1 an-2 --- a0 . a-1 --- a-m)
- Algebraic value of N ?
- N1 (1357.46)10
- N1 evaluated as ?
3Number systems and codes
- N a polynomial of radix r
- For radix r, digit set is 0, --- ?
- Hexadecimal r 16
- Digit set 0, --- ?
- Why has arithmetic evolved around radix 10?
- Which radix do you think is the most efficient?
4 3500 BC, Egyptians, nonpositional 2500 BC,
Sumerians, positional, base 60 Today
5 Numeric conversions
binary to octal 10111011001 --gt 10 111 011 001
--gt 2731 (substitution) binary to hex
10111011001 --gt 101 1101 1001 --gt
5D9 (substitution) binary to decimal 10111011001
--gt 1 (1024) 0 (512) 1 (256) 1 (128) 1
(64) 0 (32) 1 (16) 1 (8) 0 (4) 0
(2) 1 (1) 1497 (summation)
hex to binary 5D9 --gt 0101 1101 1001 --gt
10111011001 (substitution) hex to octal 5D9
--gt 0101 1101 1001 --gt 010 111 011 001 --gt
2731 (substitution) hex to decimal 5D9 --gt 5
(256) 13 (16) 9 (1) 1497 (summation)
octal to binary 2731 --gt 010 111 011 001 --gt
10111011001 (substitution) octal to hex
2731 --gt 010 111 011 001 --gt 0101 1101 1001 -gt
5D9 (substitution) octal to decimal 2731 --gt 2
(512) 7 (64) 3 (8) 1 (1) 1497 (summation)
6 Base conversions
- (10111)2 (?)10
- 20 21 22 24 23
- (274)8 (?)10
- (A)rS (?)rD
7 Base conversions
- If source radix rS lt destination radix rD then
- Every digit in the source number system is also a
digit in the destination number system simply
evaluate polynomial in destination number system - If source radix rS gt destination radix rD
- (97)10 ( ? )2
- N dn-1rSn-1 d0rS0
- yp-1rDp-1 y0rD0
- Q How do we find the yp-1y0 coefficients?
8 Base conversions
- Q1
- N (yp-1rDp-2 y1)rD y0
- ? N modulo rD y0
- Q1 modulo rD y1
- Q2 modulo rD y2
- When do we stop?
9 Base conversions
- Q N i 0
- While (Q ? 0) do
- digit i Q mod rD
- Q Q/rD
- End-while
- Division is expensive.
- Question is there a way to avoid division
(replace it with , ?, ? and possibly some table
lookups?
10 Converting fractions
- f d-1rS-1 d-2rS-2 y-1rD-1
y-2rD-2 - frD y-1 y-2rD-1
- Integer fractional
- ? ?frD? y-1 ?n? floor
- ?f1rD? y-2
- .................. When do we stop?