Presentation is loading. Please wait.

Presentation is loading. Please wait.

Number systems and codes

Similar presentations


Presentation on theme: "Number systems and codes"— Presentation transcript:

1 Number systems and codes
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

2 Number systems and codes
Positional notation N = (an-1 an a0 . a a-m) Algebraic value of N = ? N1 = ( )10 N1 evaluated as ?

3 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”?

4 3500 BC, Egyptians, nonpositional
2500 BC, Sumerians, positional, base 60 Today:

5 Numeric conversions binary to octal: > > 2731 (substitution) binary to hex: > > 5D9 (substitution) binary to decimal: > 1 (1024) + 0 (512) + 1 (256) + 1 (128) + 1 (64) (32) + 1 (16) + 1 (8) + 0 (4) + 0 (2) + 1 (1) = (summation) hex to binary: 5D9 --> > (substitution) hex to octal: 5D9 --> > > 2731 (substitution) hex to decimal: 5D9 --> 5 (256) + 13 (16) + 9 (1) = (summation) octal to binary: > > (substitution) octal to hex: > > > 5D9 (substitution) octal to decimal: > 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 < 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?

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 Division is expensive. 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 + … f•rD = y-1 + y-2rD-1 Integer fractional  f•rD = y-1 n = floor f1•rD = y-2 When do we stop? } }


Download ppt "Number systems and codes"

Similar presentations


Ads by Google