100 likes | 116 Views
Number 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 {0…9}; radix = 10 Binary: 2 digits {0, 1}; radix = 2. Number systems and codes. Positional notation
E N D
Number 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 {0…9}; radix = 10 Binary: 2 digits {0, 1}; radix = 2
Number 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 ?
Number 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”?
3500 BC, Egyptians, nonpositional 2500 BC, Sumerians, positional, base 60 Today:
Numeric conversions binary to octal: 10111011001 --> 10 111 011 001 --> 2731 (substitution) binary to hex: 10111011001 --> 101 1101 1001 --> 5D9 (substitution) binary to decimal: 10111011001 --> 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 --> 0101 1101 1001 --> 10111011001 (substitution) hex to octal: 5D9 --> 0101 1101 1001 --> 010 111 011 001 --> 2731 (substitution) hex to decimal: 5D9 --> 5 (256) + 13 (16) + 9 (1) = 1497 (summation) octal to binary: 2731 --> 010 111 011 001 --> 10111011001 (substitution) octal to hex: 2731 --> 010 111 011 001 --> 0101 1101 1001 -> 5D9 (substitution) octal to decimal: 2731 --> 2 (512) + 7 (64) + 3 (8) + 1 (1) = 1497 (summation)
Base conversions (10111)2 = (?)10 20 + 21 + 22 + 24 = 23 (274)8 = (?)10 (A)rS = (?)rD
Base conversions • If source radix rS < 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 > destination radix rD (97)10 = ( ? )2 N = dn-1rSn-1 + …+d0rS0 = yp-1rDp-1 + …+y0rD0 • Q: How do we find the yp-1…y0 coefficients?
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?
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?
Converting fractions f = d-1rS-1 + d-2rS-2 + … = y-1rD-1 + y-2rD-2 + … f•rD = y-1 + y-2rD-1 Integer fractional f•rD = y-1n = floor f1•rD = y-2 .................. When do we stop? } }