Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 110 – Intro to Computing Lecture 4: Arithmetic in other bases & Encoding Data.

Similar presentations


Presentation on theme: "CSC 110 – Intro to Computing Lecture 4: Arithmetic in other bases & Encoding Data."— Presentation transcript:

1 CSC 110 – Intro to Computing Lecture 4: Arithmetic in other bases & Encoding Data

2 Announcements Copies of the slides are available on Blackboard and the course web page before and after each class Your slips selecting your service learning site are due next Tuesday

3 Announcements Homework #1 will be handed out today (and is on the course web page). It is due in my box by Monday at 4PM Quiz #1 on numerical systems will be given next Thursday in class

4 Review of Important Bases Binary (base-2) uses 2 digits: 0 & 1 Octal (base-8) uses 8 digits: 0, 1, 2, 3, 4, 5, 6, 7 Decimal (base-10) uses 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Hexadecimal (base-16) uses 16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

5 Converting To Decimal We use positional notation to convert 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

6 Converting From Decimal Converting a number 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

7 Converting Binary To Octal Starting at the right, split into groupings of 3 bits For each group (working from right to left) Convert group from binary to decimal Add decimal number to left-end of solution

8 Converting Octal To Binary For each digit (working from right to left) Convert the digit from decimal to binary Add 0s to left of the binary to fill 3 bits Add binary number to left-end of solution Finally, remove any 0s padding leftmost digit

9 Binary to powers-of-two bases Conversion similar to binary ↔ octal  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 When converting to hexadecimal, remember to use A, B, C, D, E, F and not 10, 11, 12, 13, 14, 15 for digits

10 Decimal Addition How do we add: 5763 +1263

11 Decimal Addition How do we add: 57633 ones +1263 +3 ones 6 ones

12 Decimal Addition How do we add: 57633 ones +1263 +3 ones 66 ones

13 Decimal Addition How do we add: 57636 tens +1263 +6 tens 612 tens

14 Decimal Addition How do we add: 57636 tens +1263 +6 tens 6 1 hundred 2 tens

15 Decimal Addition How do we add: 1 57639 tens +1233 +3 tens 26 1 hundred 2 tens

16 Decimal Addition How do we add: 1 1 1 hundred 57637 hundreds +1263 +2 hundreds 026 1 thousand 0 hundred

17 Decimal Addition How do we add: 1 1 1 thousand 57635 thousand +1263 +1 thousand 7026 7 thousand

18 Decimal Addition How do we add: 1 1 5763 +1263 7026

19 Oops… I forgot one detail I forgot this was supposed to be in octal 8383 8282 8181 8080 5763838 +1263838

20 Adding in Octal I forgot this was supposed to be in octal 8383 8282 8181 8080 5763838 +1263838 3 ones +3 ones 6 ones

21 Adding in Octal I forgot this was supposed to be in octal 8383 8282 8181 8080 5763838 +1263838 6868 3 ones +3 ones 6 ones Whew. 6 10 = 6 8

22 Adding in Octal 8 1 = 8 8 2 = 8 * 8 = 64 8383 8282 8181 8080 5763838 +1263838 6868 6 eights +6 eights 12 eights What do we do now?

23 Adding in Octal 8 1 = 8 8 2 = 8 * 8 = 64 8383 8282 8181 8080 5763838 +1263838 6868 6 eights +6 eights 12 eights 8 eights = 1 sixty-four

24 Adding in Octal 8 1 = 8 8 2 = 8 * 8 = 64 8383 8282 8181 8080 5763838 +1263838 6868 6 eights +6 eights 12 eights –or– 12-8 = 4 eights and 1 sixty-four

25 Adding in Octal 8 1 = 8 8 2 = 8 * 8 = 64 8383 8282 8181 8080 1 5763838 +1263838 46868 6 eights +6 eights 4 eights and 1 sixty-four

26 Adding in Octal 8 2 = 64 8383 8282 8181 8080 1 5763838 +1263838 46868 1 sixty-four 7 sixty-four +2 sixty-four 10 sixty-fours

27 Adding in Octal 8 2 = 648 3 = 64 * 8 = 256 8383 8282 8181 8080 11 5763838 +1263838 246868 1 sixty-four 7 sixty-four +2 sixty-four 10-8 = 2 sixty-fours 1 two fifty-six

28 Adding in Octal Finally, something makes sense again 8383 8282 8181 8080 11 5763838 +1263838 7246868 1 two fifty-six 5 two fifty-six +1 two fifty-six 7 two fity-six Yes! 7 is an octal digit

29 Adding in Octal That’s all, folks! 8383 8282 8181 8080 11 5763838 +1263838 7246868

30 Algorithm For each position from right to left 126868 +722828

31 Addition Algorithm To add 2 numbers in base-b: For each position from right to left Compute sum of the digits If sum > b then Record sum - b at position Carry the 1 If sum < b Record sum at position

32 Algorithm For each position from right to left 126868 +722828

33 Algorithm Compute sum of the digits6 + 2 = 8 126868 +722828

34 Algorithm If sum > b thenIf 8 > 8 then 126868 +722828

35 Algorithm Record sum - b for position8 – 8 = 0 126868 +722828 0808

36 Algorithm Carry the one 1 126868 +722828 0808

37 Algorithm For each position from right to left 1 126868 +722828 0808

38 Algorithm Compute sum of digits1 + 2 + 2 = 5 1 126868 +722828 0808

39 Algorithm If sum < b then 5 < 8 1 126868 +722828 0808

40 Algorithm Record sum for position 1 126868 +722828 50808

41 Algorithm For each position from right to left 1 126868 +722828 50808

42 Algorithm Compute sum of digits1 + 7 = 8 1 126868 +722828 50808

43 Algorithm If sum > b then8 > 8 1 126868 +722828 50808

44 Algorithm Record sum – b for position8 – 8 = 0 1 126868 +722828 050808

45 Algorithm Carry the one 11 126868 +722828 050808

46 Algorithm For each position from right to left 11 126868 +722828 050808

47 Algorithm Compute sum of digits1 = 1 11 126868 +722828 050808

48 Algorithm If sum < b then 1 < 8 11 126868 +722828 050808

49 Algorithm Record sum for position 11 126868 +722828 1050808

50 Algorithm We’re Done! 11 126868 +722828 1050808

51 Addition Algorithm To add numbers in base-b: For each position from right to left Compute sum of the digits If sum > b then Record sum - b at positionCarry the 1 If sum < b Record sum at position

52 Data Encoding In the real world, data (“information”) is analog  Falls along a infinite continuum Color changes when mixing paint Falling mercury levels as temperatures drop  Hard to capture numerically Is it 31.848174 o F or 31.848173 o F right now? Do you even care about this difference?

53 Data Encoding Normally, we work with discrete numbers  Round to nearest whole or rational number: 71 o F, 4.5 miles, 1 teaspoon  Limits the amount of space needed Imagine if the morning news had to put on screen: 71.23478923478234789234890234234789 o F or state the time as: 8:45:12.484589983890234890234890234890234 Computers follow this pattern  It takes a lot of space to be precise!

54 Digitizing Data Computers work in binary (0-1)  Good news: we know how to convert any number into binary!  Suppose we have a CD containing pictures of my daughter, how do we turn the 0s and 1s on a CD into the colors that make up the cutest girl ever?

55 Color by Number Most pictures rely upon the RGB standard  First 8 bits (“byte”) specify amount of red used  Next byte specifies amount of green used  Last byte specifies amount of blue used  Mixing these numbers gives us many colors

56 Data Storage Storing data can require lots of space  Each pixel (dot) in a color photo takes 4 bytes  5 megapixel (~million pixel) camera: 20MB per picture  32 pictures: 640MB (a CD holds 650MB)

57 Binary Representation 1 bit captures 2 states: 0 or 1 2 bits captures 4 states: 00, 01, 10, 11 3 bits capture 8 states: 000, 001, 010, 011, 100, 101, 110, 111

58 Binary Representation How many colors can 8 bits generate? How many different colors can n bits represent?

59 For Next Lecture Have Chapter 4 started Be ready to discuss:  Boolean logic  AND, OR, XOR, NOT, NAND, NOR gates


Download ppt "CSC 110 – Intro to Computing Lecture 4: Arithmetic in other bases & Encoding Data."

Similar presentations


Ads by Google