Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 110 – Intro to Computing Lecture 3: Converting between bases & Arithmetic in other bases.

Similar presentations


Presentation on theme: "CSC 110 – Intro to Computing Lecture 3: Converting between bases & Arithmetic in other bases."— Presentation transcript:

1 CSC 110 – Intro to Computing Lecture 3: Converting between bases & Arithmetic in other bases

2 Announcements The end is near! All drop/add slips must be turned in by Jan. 24 th. I have a cool office with a full candy jar. Please stop by and get your sugar fix (you could also me questions you have at the same time).

3 Positional Notation Usually write numbers using positional notation  Add numbers from right-to-left  Digits (0, 1, 2, … 9) have a numerical value  Each position has an place value  E.g., 1275, 529, 3, 200 Makes understanding number and arithmetic easy

4 Positional Notation for 5862 2= 2 ones= 2 * 1 =2

5 Positional Notation for 5862 2= 2 ones= 2 * 1 =2 6= 6 tens= 6 * 10 =60

6 Positional Notation for 5862 2= 2 ones= 2 * 1 =2 6= 6 tens= 6 * 10 =60 8= 8 hundreds= 8 * 100 =800

7 Positional Notation for 5862 2= 2 ones= 2 * 1 =2 6= 6 tens= 6 * 10 =60 8= 8 hundreds= 8 * 100 =800 5= 5 thousands= 5 * 1000 =5000

8 Positional Notation for 5862 2= 2 ones= 2 * 1 =2 6= 6 tens= 6 * 10 =60 8= 8 hundreds= 8 * 100 =800 5= 5 thousands= 5 * 1000 =+ 5000 5862

9 Decimal Positional Notation Formal equation for a number d n...d 3 d 2 d 1 d 0  d 0 is digit in ones place, d 1 is in tens place, … d 0 * 10 0 d 1 * 10 1 d 2 * 10 2 d 3 * 10 3 … + d n * 10 n

10 Decimal Positional Notation 2= 2 * 1= 2 * 10 0 =2 6= 6 * 10= 6 * 10 1 =60 8= 8 * 100= 8 * 10 2 =800 5= 5 * 1000= 5 * 10 3 =+ 5000 5862

11 Bases Used With Computers Previous equation of positional notation assumes base-10 Computer use other bases  Binary (base-2)  Octal (base-8)  Hexadecimal (base-16) We use positional notation to convert from these bases into decimal

12 Positional Notation Convert a number d n...d 3 d 2 d 1 d 0 to decimal: From base-b d 0 * b 0 d 1 * b 1 d 2 * b 2 d 3 * b 3 … + d n * b n From base-10 d 0 * 10 0 d 1 * 10 1 d 2 * 10 2 d 3 * 10 3 … + d n * 10 n

13 Converting Binary to Decimal 101011 2 =1 * 2 0 = 1 * 2 1 = 0 * 2 2 = 1 * 2 3 = 0 * 2 4 = + 1 * 2 5 =

14 Converting Binary to Decimal 101011 2 =1 * 2 0 =1 * 1 1 * 2 1 =1 * 2 0 * 2 2 =0 * 4 1 * 2 3 =1 * 8 0 * 2 4 =0 * 16 1 * 2 5 = 1 * 32

15 Converting Binary to Decimal 101011 2 =1 * 2 0 =1 * 1= 1 1 * 2 1 =1 * 2= 2 0 * 2 2 =0 * 4= 0 1 * 2 3 =1 * 8= 8 0 * 2 4 =0 * 16= 0 1 * 2 5 =1 * 32+ 32 43 10

16 Converting Octal to Decimal 106 8 =6 * 8 0 = 0 * 8 1 = + 1 * 8 2 =

17 Converting Octal to Decimal 106 8 =6 * 8 0 =6 * 1 0 * 8 1 =0 * 8 1 * 8 2 =1 * 64

18 Converting Octal to Decimal 106 8 =6 * 8 0 =6 * 1= 6 0 * 8 1 =0 * 8= 0 1 * 8 2 =1 * 64 + 64 70 10

19 Digits In Other Bases Binary only needs 2 digits: 0 & 1 Octal needs 8 digits: 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal (base-16) uses 16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F  A has value of 10 10  B has value of 11 10  C has value of 12 10  D has value of 13 10  E has value of 14 10  F has value of 15 10

20 Convert Hexadecimal To Decimal 3F 16 = 27 16 =

21 Convert Hexadecimal To Decimal 3F 16 =15 * 16 0 =15 * 1 =15 3 * 16 1 =3 * 16 =+ 48 63 10 27 16 =7 * 16 0 =7 * 1 =7 2 * 16 1 =2 * 16 =+ 32 39 10

22 Converting To Decimal Review Formula converting a number d n...d 3 d 2 d 1 d 0 from base-b to decimal: d 0 * b 0 d 1 * b 1 d 2 * b 2 d 3 * b 3 … + d n * b n

23 Converting Decimal To Binary Algorithm converting from decimal to binary: While the decimal number is not 0 Divide the decimal number by 2 Move remainder to left end of answer Replace decimal number with quotient 34 10 =

24 Converting Decimal To Base-b More generally, converting from decimal to base-b While the decimal number is not 0 Divide the decimal number by b Move remainder to left end of answer Replace decimal number with quotient 335 10 =

25 Converting Binary to Octal Special relationship between these bases  Octal uses 8 digits: 0, 1, 2, 3, 4, 5, 6, 7  3 binary digits (bits) can represent 8 numbers: 000 2 = 0 10 100 2 = 4 10 001 2 = 1 10 101 2 = 5 10 010 2 = 2 10 110 2 = 6 10 011 2 = 3 10 111 2 = 7 10  Every 3 bits is equal to one octal digit  Makes conversion easy

26 Converting Binary to Octal Starting from the right, split the number into groupings of 3 bits: 1110011010 2

27 Converting Binary to Octal Starting from the right, split the number into groupings of 3 bits: 1 110 011 010

28 Converting Binary to Octal Convert each group to decimal: 1 110 011 010 010 2 =

29 Converting Binary to Octal Convert each group to decimal: 1 110 011 010 2 010 2 =0 * 2 0 =0 * 1 =0 1 * 2 1 =1 * 2 =2 0 * 2 2 =0 * 4 =+ 0 2

30 Converting Binary to Octal Convert each group to decimal: 1 110 011 010 3 2 011 2 =1 * 2 0 =1 * 1 =1 1 * 2 1 =1 * 2 =2 0 * 2 2 =0 * 4 =+ 0 3

31 Converting Binary to Octal Convert each group to decimal: 1 110 011 010 6 3 2 110 2 =0 * 2 0 =0 * 1 =0 1 * 2 1 =1 * 2 =2 1 * 2 2 =1 * 4 =+ 4 6

32 Converting Binary to Octal Convert each group to decimal: 1 110 011 0101 6 3 2 1 2 =1 * 2 0 =1 * 1 =1

33 Converting Binary to Octal That’s all there us to it! 1110011010 2 = 1632 8

34 Converting Octal to Binary Starting from the right, convert each digit into binary: 235 8

35 Converting Octal to Binary Starting from the right, convert each digit into binary: 2 3 5 5 10

36 Converting Octal to Binary Starting from the right, convert each digit into binary: 2 3 5 101 5 10 = 101 2

37 Converting Octal to Binary Starting from the right, convert each digit into binary: 2 3 5 101 3 10 = 11 2

38 Converting Octal to Binary Add 0s to the left to pad solution to 3 digits 2 3 5 011 101 3 10 = 011 2

39 Converting Octal to Binary Starting from the right, convert each digit into binary: 2 3 5010 011 101 2 10 = 010 2

40 Converting Octal to Binary Remove any 0 padding the rightmost digit: 2 3 5 10 011 101

41 Converting Octal to Binary That’s it! 235 8 = 10011101 2

42 Binary to powers-of-two bases Special relationship between binary and any power-of-two base  Octal is base 8 2 3 = 8 3 binary digits represent 1 octal digit  Hexadecimal is base 16 2 4 = 16 4 binary digits represent 1 hexadecimal digit

43 Converting Between Binary & Hex Conversion from binary to hexadecimal is similar to binary to octal  Initially make groupings of 4 bits, not 3 bits Similarly, converting hexadecimal to binary is like converting octal to binary  But converting hex to binary means we pad each result out to 4 bits

44 For Next Lecture Read through Chapter 3 Be ready to discuss:  Arithmetic in bases other than 10  Ways computers representation information


Download ppt "CSC 110 – Intro to Computing Lecture 3: Converting between bases & Arithmetic in other bases."

Similar presentations


Ads by Google