Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMPE12cGabriel Hugh Elkaim 1 Number Systems. CMPE12cGabriel Hugh Elkaim 2 A Brief History of Numbers From Gonick, Cartoon Guide to Computer Science.

Similar presentations


Presentation on theme: "CMPE12cGabriel Hugh Elkaim 1 Number Systems. CMPE12cGabriel Hugh Elkaim 2 A Brief History of Numbers From Gonick, Cartoon Guide to Computer Science."— Presentation transcript:

1 CMPE12cGabriel Hugh Elkaim 1 Number Systems

2 CMPE12cGabriel Hugh Elkaim 2 A Brief History of Numbers From Gonick, Cartoon Guide to Computer Science

3 CMPE12cGabriel Hugh Elkaim 3

4 CMPE12cGabriel Hugh Elkaim 4

5 CMPE12cGabriel Hugh Elkaim 5 Prehistoric Ledgers

6 CMPE12cGabriel Hugh Elkaim 6

7 CMPE12cGabriel Hugh Elkaim 7 Elaborate Finger Counting

8 CMPE12cGabriel Hugh Elkaim 8

9 CMPE12cGabriel Hugh Elkaim 9

10 CMPE12cGabriel Hugh Elkaim 10

11 CMPE12cGabriel Hugh Elkaim 11 Ancient Number Systems

12 CMPE12cGabriel Hugh Elkaim 12

13 CMPE12cGabriel Hugh Elkaim 13 Positional Number Systems

14 CMPE12cGabriel Hugh Elkaim 14

15 CMPE12cGabriel Hugh Elkaim 15

16 CMPE12cGabriel Hugh Elkaim 16

17 CMPE12cGabriel Hugh Elkaim 17

18 CMPE12cGabriel Hugh Elkaim 18

19 CMPE12cGabriel Hugh Elkaim 19 Number Systems Prehistory Unary, or marks: /////// = 7 /////// + ////// = ///////////// Grouping lead to Roman Numerals: VII + V = VVII = XII Better, Arabic Numerals: 7 + 5 = 12 = 1 x 10 + 2

20 CMPE12cGabriel Hugh Elkaim 20 Positional Number System Base 10 is a special case of positional number system PNS First used over 4000 years ago in Mesopotamia (Iraq) –Base 60 –0...59 (written as 60 different symbols) –5,45 60 = 5 x 60 + 45 = 345 10 Positional Number Systems are great for algebra Why?

21 CMPE12cGabriel Hugh Elkaim 21 Arabic Numerals 345 is really –3 x 10 2 + 4 x 10 1 + 5 x 10 0 –3 x 100 + 4 x 10 + 5 x 1 –3 is the most significant symbol (carries the most weight) –5 is the least significant symbol (carries the least weight) Digits (or symbols) allowed: 0-9 Base (or radix): 10

22 CMPE12cGabriel Hugh Elkaim 22 Try multiplication in (non-positional) Roman numerals! XXXIII (33 in decimal) XII (12 in decimal) --------- XXXIII CCCXXX ----------- CCCXXXXXXXXXIIIIII ----------- CCCLXXXXVI ----------- CCCXCVI = 396 in decimal Positional Number System The Mesopotamians wouldn’t have had this problem!! * +

23 CMPE12cGabriel Hugh Elkaim 23 There are many ways to “represent” a number Representation does not affect computation result LIX+XXXIII= LXXXXII(Roman) 59+33= 92(Decimal) Representation affects difficulty of computing results Computers need a representation that works with fast electronic circuits Positional numbers work great with 2-state devices Positional Number System

24 CMPE12cGabriel Hugh Elkaim 24

25 CMPE12cGabriel Hugh Elkaim 25

26 CMPE12cGabriel Hugh Elkaim 26 What ’10’ Means

27 CMPE12cGabriel Hugh Elkaim 27 Number Base Systems

28 CMPE12cGabriel Hugh Elkaim 28 Binary Numbers

29 CMPE12cGabriel Hugh Elkaim 29

30 CMPE12cGabriel Hugh Elkaim 30 The Powers of 2

31 CMPE12cGabriel Hugh Elkaim 31

32 CMPE12cGabriel Hugh Elkaim 32 Equivalent Numbers

33 CMPE12cGabriel Hugh Elkaim 33 Converting Binary to Decimal

34 CMPE12cGabriel Hugh Elkaim 34 Base (radix): 2 Digits (symbols) allowed: 0, 1 Binary Digits, or bits 1001 2 is really 1 x 2 3 + 0 x 2 2 + 0 X 2 1 + 1 X 2 0 9 10 11000 2 is really 1 x 2 4 + 1 x 2 3 + 0 x 2 2 + 0 x 2 1 + 0 x 2 0 24 10 Binary Number System

35 CMPE12cGabriel Hugh Elkaim 35 Computers multiply Arabic numerals by converting to binary, multiplying and converting back (much as us with Roman numerals) Binary Number System So if the computer is all binary how does it multiply 5 by 324 when I type it in the calculator program?

36 CMPE12cGabriel Hugh Elkaim 36 Octal Number System Base (radix): 8 Digits (symbols): 0 – 7 345 8 is really –3 x 8 2 + 4 x 8 1 + 5 x 8 0 –192 + 32 + 5 –229 10 1001 8 is really –1 x 8 3 + 0 x 8 2 + 0 x 8 1 + 1 x 8 0 –512 + 1 –513 10 In C, octal numbers are represented with a leading 0 (0345 or 01001).

37 CMPE12cGabriel Hugh Elkaim 37 Hexadecimal Number System Base (radix): 16 Digits (symbols) allowed: 0 – 9, a – f HexDecimal a10 b11 c12 d13 e14 f15

38 CMPE12cGabriel Hugh Elkaim 38 A3 16 is really: A x 16 1 + 3 x 16 0 160 + 3 163 10 3E8 16 is really: 3 x 16 2 + E x 16 1 + 8 x 16 0 3 x 256 + 14 x 16 + 8 x 1 768 + 224 + 8 1000 10 Hexadecimal Number System Some Examples of converting hex numbers to decimal

39 CMPE12cGabriel Hugh Elkaim 39 10C 16 is really: 1 x 16 2 + 0 x 16 1 + C x 16 0 1 x 256 + 12 x 16 256 + 192 448 10 In C, hex numbers are represented with a leading “0x” (for example “0xa3” or “0x10c”). Hexadecimal Number System

40 CMPE12cGabriel Hugh Elkaim 40 For any positional number system Base (radix): b Digits (symbols): 0 … b – 1 S n-1 S n-2 ….S 2 S 1 S 0 Use summation to transform any base to decimal Value = Σ (S i b i ) n-1 i=0 Positional Number System

41 CMPE12cGabriel Hugh Elkaim 41 More PNS fun 2120 3 = 403 5 = 27 17 = 356 9 = 1110 2 = 2A6 12 = BEEF 16 = =69 10 =103 10 =41 10 =294 10 =14 10 =414 10 =48879 10

42 CMPE12cGabriel Hugh Elkaim 42 Decimal  Binary Conversion Divide decimal value by 2 until the value is 0 Know your powers of two and subtract … 256 128 64 32 16 8 4 2 1 Example: 42 What is the biggest power of two that fits? What is the remainder? What fits? What is the remainder? What fits? What is the binary representation?

43 CMPE12cGabriel Hugh Elkaim 43 Decimal  Binary Conversion

44 CMPE12cGabriel Hugh Elkaim 44 Decimal  Binary Conversion 128 10 = 310 10 = 26 10 =

45 CMPE12cGabriel Hugh Elkaim 45 Binary  Octal Conversion Group into 3’s starting at least significant symbol Add leading 0’s if needed (why not trailing?) Write 1 octal digit for each group Examples: 100 010 111 (binary) 4 2 7 (octal) 10 101 110 (binary) 2 5 6 (octal)

46 CMPE12cGabriel Hugh Elkaim 46 Octal  Binary Conversion It is simple, just write down the 3-bit binary code for each octal digit OctalBinary 0000 1001 2010 3011 4100 5101 6110 7111

47 CMPE12cGabriel Hugh Elkaim 47 Binary  Hex Conversion Group into 4’s starting at least significant symbol | Adding leading 0’s if needed Write 1 hex digit for each group Examples: 1001 1110 0111 0000 9 e 7 0 0001 1111 1010 0011 1 f a 3

48 CMPE12cGabriel Hugh Elkaim 48 Hex  Binary Conversion Again, simply write down the 4 bit binary code for each hex digit Example: 3 9 c 8 0011 1001 1100 1000

49 CMPE12cGabriel Hugh Elkaim 49 Conversion Table DecimalHexadecimalOctalBinary 0000000 1110001 2220010 3330011 4440100 5550101 6660110 7770111 88101000 99111001 10A121010 11B131011 12C141100 13D151101 14E161110 15F171111

50 CMPE12cGabriel Hugh Elkaim 50

51 CMPE12cGabriel Hugh Elkaim 51 Hex  Octal Do it in 2 steps, hex  binary  octal Decimal  Hex Do it in 2 steps, decimal  binary  hex So why use hex and octal and not just binary and decimal?

52 CMPE12cGabriel Hugh Elkaim 52 Negative Integers Most humans precede number with “-” (e.g., -2000) Accountants, however, use parentheses: (2000) or color 2000 Sign-magnitude format Example: -1000 in hex? 1000 10 = 3 x 16 2 + e x 16 1 + 8 x 16 0 -3E8 16

53 CMPE12cGabriel Hugh Elkaim 53 Mesopotamians used positional fractions Sqrt(2)= 1.24,51,10 60 = 1 x 60 0 + 24 x 60 -1 + 51 x 60 -2 + 10 x 60 -3 = 1.414222 10 Most accurate approximation until the Renaissance

54 CMPE12cGabriel Hugh Elkaim 54 f n-1 f n-2 … f 2 f 1 f 0 f -1 f -2 f -3 … f m-1 Radix point Generalized Representation For a number “f” with ‘n’ digits to the left and ‘m’ to the right of the decimal place Position is the power

55 CMPE12cGabriel Hugh Elkaim 55 Fractional Representation What is 3E.8F 16 ? How about 10.101 2 ? = 3 x 16 1 + E x 16 0 + 8 x 16 -1 + F x 16 -2 = 48 + 14 + 8/16 + 15/256 = 1 x 2 1 + 0 x 2 0 + 1 x 2 -1 + 0 x 2 -2 + 1 x 2 -3 = 2 + 0 + 1/2 + 1/8

56 CMPE12cGabriel Hugh Elkaim 56 More PNS Fractional Fun 21.012 3 = 4.133 5 = 22.61 7 = A.3A 12 =

57 CMPE12cGabriel Hugh Elkaim 57 Converting Decimal  Binary fractions Consider left and right of the decimal point separately. The stuff to the left can be converted to binary as before. Use the following table/algorithm to convert the fraction

58 CMPE12cGabriel Hugh Elkaim 58 FractionFraction x 2Digit left of decimal point 0.81.61  most significant (f -1 ) 0.61.21 0.20.40 0.80 (it must repeat from here!!) Different bases have different repeating fractions. 0.8 10 = 0.110011001100… 2 = 0.1100 2 Numbers can repeat in one base and not in another. For 0.8 10 to binary

59 CMPE12cGabriel Hugh Elkaim 59 What is 2.2 10 in: Binary Hex

60 CMPE12cGabriel Hugh Elkaim 60

61 CMPE12cGabriel Hugh Elkaim 61


Download ppt "CMPE12cGabriel Hugh Elkaim 1 Number Systems. CMPE12cGabriel Hugh Elkaim 2 A Brief History of Numbers From Gonick, Cartoon Guide to Computer Science."

Similar presentations


Ads by Google