Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science Introduction to the Number Base Unit Adapted from Slides by John Owen Computer Science Instructor, Rockport-Fulton High School, Rockport,

Similar presentations


Presentation on theme: "Computer Science Introduction to the Number Base Unit Adapted from Slides by John Owen Computer Science Instructor, Rockport-Fulton High School, Rockport,"— Presentation transcript:

1 Computer Science Introduction to the Number Base Unit Adapted from Slides by John Owen Computer Science Instructor, Rockport-Fulton High School, Rockport, Texas

2 John Owen, Rockport Fulton HS2 Objective This unit of study is designed to introduce the beginner computer science students to the concept of the computer number bases (2, 8, and 16) and their computation.

3 John Owen, Rockport Fulton HS3 Part1 Different Number Bases, specifically about those used by the computer includes: Base Two – binary Base Eight – octal Base Sixteen – hexadecimal

4 John Owen, Rockport Fulton HS4 Base Ten “because it has ten counting digits, 0,1,2,3,4,5,6,7,8, and 9” To count in base ten, you go from 0 to 9, then do combinations of two digits starting with 10 all the way to 99

5 John Owen, Rockport Fulton HS5 Base Two To count in base two, which only has 0 and 1 as counting digits, you count 0,1, then switch to two digit combinations, 10,11, then to three digit combos, 100, 101,110,111, then four digit, 1000, _____,_______, …, 1111

6 John Owen, Rockport Fulton HS6 Base Three To count in base three, which has 0, 1, and 2 as counting digits, you count 0,1,2, then switch to two digit combinations, 10,11, 12, 20, 21, 22, then to three digit combos, 100, 101,102, 110,111, 112, etc…

7 John Owen, Rockport Fulton HS7 Base Eight base eight (often called octal)… The base eight counting sequence 0,1,2,3,4,5,6,7,10,11,12,13,…77 100,101,102,103,104,105,106,10 7110,111, etc.

8 John Owen, Rockport Fulton HS8 Base Sixteen Base Sixteen, also known as hexadecimal, was especially created by computer scientists to help simplify low-level programming, like machine language and assembly language.

9 John Owen, Rockport Fulton HS9 Base Sixteen To get sixteen counting digits, you use 0- 9, but still need six more…so it was decided to use A,B,C,D,E, and F. 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F Then the two-digit combos: 10,11,12,…19,1A,1B,1C,1D,1E,1F,20,21,22,…2D,2E,2F,30,31,…FF

10 John Owen, Rockport Fulton HS10 Base conversion To convert from base ten to another base, such as base two, eight, or sixteen, is an important skill for computer scientists and programmers.

11 John Owen, Rockport Fulton HS11 Base Ten to Base Two Let’s take the value 27 and convert it into base 2. Here’s the process: Divide 27 by 2 The answer is 13, remainder 1 Divide 13 by 2 Answer is 6, remainder 1

12 John Owen, Rockport Fulton HS12 Base Ten to Base Two Continue until the answer is 1. 6 divided by 2 = 3, remainder 0 3 divided by 2 = 1, remainder 1 Now take the last answer, 1, and all of the remainders in reverse order, and put them together…11011 27 base 10 = 11011 base two

13 John Owen, Rockport Fulton HS13 Base Ten to Base Two Here’s an easy way to do it on paper 27 divided by 2 = 13, R 1

14 John Owen, Rockport Fulton HS14 Base Ten to Base Two 13 / 2 = 6, R 1

15 John Owen, Rockport Fulton HS15 Base Ten to Base Two 6 / 2 = 3, R 0

16 John Owen, Rockport Fulton HS16 Base Ten to Base Two 3 / 2 = 1, R 1

17 John Owen, Rockport Fulton HS17 Base Ten to Base Two Stop, and write the answer

18 John Owen, Rockport Fulton HS18 Base Ten to Base Two

19 John Owen, Rockport Fulton HS19 Exercises Now try a few yourself (see last slide for answers): 1. 16 10 = _________ 2 2. 47 10 = _________ 2 3. 145 10 = _________ 2 4. 31 10 = _________ 2 5. 32 10 = _________ 2

20 John Owen, Rockport Fulton HS20 Base Ten to Base Eight Let’s again take the value 27 and convert it into base 8. Same process: Divide 27 by 8 The answer is 3, remainder 3 Stop! You can’t divide anymore because the answer is less than 8

21 John Owen, Rockport Fulton HS21 Base Ten to Base Eight The last answer was 3, and the only remainder was 3, so the base eight value is 33, base 8.

22 John Owen, Rockport Fulton HS22 Base Ten to Base Eight Use the same method on paper 27 divided by 8 = 3, R 3 27, base 10 = 33, base 8

23 John Owen, Rockport Fulton HS23 Exercises Now try the same values for base eight. 6. 16 10 = _________ 8 7. 47 10 = _________ 8 8. 145 10 = _________ 8 9. 31 10 = _________ 8 10. 32 10 = _________ 8

24 John Owen, Rockport Fulton HS24 Base Ten to Base Sixteen Finally we’ll convert 27 into base 16. Divide 27 by 16 The answer is 1, remainder 11 Stop! You can’t divide anymore because the answer is less than 16

25 John Owen, Rockport Fulton HS25 Base Ten to Base Sixteen The last answer was 1, and the only remainder was 11, which in base 16 is the letter B, so the base sixteen value is 1B, base 16.

26 John Owen, Rockport Fulton HS26 Base Ten to Base Sixteen Again, the same method on paper 27 divided by 16 = 1, R 11 or B 27, base 10 = 1B, base 16

27 John Owen, Rockport Fulton HS27 Exercises And now try base sixteen! 11. 16 10 = _________ 16 12. 47 10 = _________ 16 13. 145 10 = _________ 16 14. 31 10 = _________ 16 15. 32 10 = _________ 16

28 John Owen, Rockport Fulton HS28 Here are the answers to the exercises, in jumbled order 10 1F 20 20 2F 37 40 57 91 221 1000011111 10111110000010010001

29 John Owen, Rockport Fulton HS29 Part 2: Other conversions Now you will learn other conversions among these four number systems, specifically: Binary to Decimal Octal to Decimal Hexadecimal to Decimal

30 John Owen, Rockport Fulton HS30 Other conversions As well as Binary to Octal Octal to Binary Binary to Hexadecimal Hexadecimal to Binary Octal to Hexadecimal Hexadecimal to Octal

31 John Owen, Rockport Fulton HS31 Binary to Decimal Each binary digit in a binary number has a place value. In the number 111, base 2, the digit farthest to the right is in the “ones” place, like the base ten system, and is worth 1. Technically this is the 2 0 place.

32 John Owen, Rockport Fulton HS32 Binary to Decimal The 2 nd digit from the right, 111, is in the “twos” place, which could be called the “base” place, and is worth 2. Technically this is the 2 1 place. In base ten, this would be the “tens” place and would be worth 10.

33 John Owen, Rockport Fulton HS33 Binary to Decimal The 3 rd digit from the right, 111, is in the “fours” place, or the “base squared” place, and is worth 4. Technically this is the 2 2 place. In base ten, this would be the “hundreds” place and would be worth 100.

34 John Owen, Rockport Fulton HS34 Binary to Decimal The total value of this binary number, 111, is 4+2+1, or seven. In base ten, 111 would be worth 100 + 10 + 1, or one-hundred eleven.

35 John Owen, Rockport Fulton HS35 Binary to Decimal Can you figure the decimal values for these binary values? 11 101 110 1111 11011

36 John Owen, Rockport Fulton HS36 Binary to Decimal answers: 11 is 3 in base ten 101 is 5 110 is 6 1111 is 15 11011 is 27

37 John Owen, Rockport Fulton HS37 Octal to Decimal Octal digits have place values based on the value 8. In the number 111, base 8, the digit farthest to the right is in the “ones” place and is worth 1. Technically this is the 8 0 place.

38 John Owen, Rockport Fulton HS38 Octal to Decimal The 2 nd digit from the right, 111, is in the “eights” place, the “base” place, and is worth 8. Technically this is the 8 1 place.

39 John Owen, Rockport Fulton HS39 Octal to Decimal The 3 rd digit from the right, 111, is in the “sixty-fours” place, the “base squared” place, and is worth 64. Technically this is the 8 2 place.

40 John Owen, Rockport Fulton HS40 Octal to Decimal The total value of this octal number, 111, is 64+8+1, or seventy-three.

41 John Owen, Rockport Fulton HS41 Octal to Decimal Can you figure the value for these octal values? 21 156 270 1164 2105

42 John Owen, Rockport Fulton HS42 Octal to Decimal Here are the answers: 21 is 17 in base 10 156 is 110 270 is 184 1164 is 628 2105 is 1093

43 John Owen, Rockport Fulton HS43 Hexadecimal to Decimal Hexadecimal digits have place values base on the value 16. In the number 111, base 16, the digit farthest to the right is in the “ones” place and is worth 1. Technically this is the 16 0 place.

44 John Owen, Rockport Fulton HS44 Hexadecimal to Decimal The 2 nd digit from the right, 111, is in the “sixteens” place, the “base” place, and is worth 16. Technically this is the 16 1 place.

45 John Owen, Rockport Fulton HS45 Hexadecimal to Decimal The 3 rd digit from the right, 111, is in the “two hundred fifty-six” place, the “base squared” place, and is worth 256. Technically this is the 16 2 place.

46 John Owen, Rockport Fulton HS46 Hexadecimal to Decimal The total value of this hexadecimal number, 111, is 256+16+1, or two hundred seventy-three.

47 John Owen, Rockport Fulton HS47 Hexadecimal to Decimal Can you figure the value for these hexadecimal values? 2A 15F A7C 11BE A10D

48 John Owen, Rockport Fulton HS48 Hexadecimal to Decimal Here are the answers: 2A is 42 in base 10 15F is 351 A7C is 2684 11BE is 4542 A10D is 41229

49 John Owen, Rockport Fulton HS49 Binary to Octal The conversion between binary and octal is quite simple. Since 2 to the power of 3 equals 8, it takes 3 base 2 digits to combine to make a base 8 digit.

50 John Owen, Rockport Fulton HS50 Binary to Octal 000 base 2 equals 0 base 8 001 2 = 1 8 010 2 = 2 8 011 2 = 3 8 100 2 = 4 8 101 2 = 5 8 110 2 = 6 8 111 2 = 7 8

51 John Owen, Rockport Fulton HS51 Binary to Octal What if you have more than three binary digits, like 110011? Just separate the digits into groups of three from the right, then convert each group into the corresponding base 8 digit. 110 011 base 2 = 63 base 8

52 John Owen, Rockport Fulton HS52 Binary to Octal Try these: 111100 100101 111001 1100101 Hint: when the leftmost group has fewer than three digits, fill with zeroes from the left: 1100101 = 1 100 101 = 001 100 101 110011101

53 John Owen, Rockport Fulton HS53 Binary to Octal The answers are: 111100 2 = 74 8 100101 2 = 45 8 111001 2 = 71 8 1100101 2 = 145 8 110011101 2 = 635 8

54 John Owen, Rockport Fulton HS54 Binary to Hexadecimal The conversion between binary and hexadecimal is equally simple. Since 2 to the power of 4 equals 16, it takes 4 base 2 digits to combine to make a base 16 digit.

55 John Owen, Rockport Fulton HS55 Binary to Hexadecimal 0000 base 2 equals 0 base 8 0001 2 = 1 16 0010 2 = 2 16 0011 2 = 3 16 0100 2 = 4 16 0101 2 = 5 16 0110 2 = 6 16 0111 2 = 7 16

56 John Owen, Rockport Fulton HS56 Binary to Hexadecimal 1000 2 = 8 16 1001 2 = 9 16 1010 2 = A 16 1011 2 = B 16 1100 2 = C 16 1101 2 = D 16 1110 2 = E 16 1111 2 = F 16

57 John Owen, Rockport Fulton HS57 Binary to Hexadecimal If you have more than four binary digits, like 11010111, again separate the digits into groups of four from the right, then convert each group into the corresponding base 16 digit. 1101 0111 base 2 = D7 base 16

58 John Owen, Rockport Fulton HS58 Binary to Hexadecimal Try these: 11011100 10110101 10011001 110110101 Hint: when the leftmost group has fewer than four digits, fill with zeroes on the left: 110110101 = 1 1011 0101 = 0001 1011 0101 1101001011101

59 John Owen, Rockport Fulton HS59 Binary to Hexadecimal The answers are: 11011100 2 = DC 16 10110101 2 = B5 16 10011001 2 = 99 16 110110101 2 = 1B5 16 1 1010 0101 1101 2 = 1A5D 16

60 John Owen, Rockport Fulton HS60 Octal to Binary Converting from Octal to Binary is just the inverse of Binary to Octal. For each octal digit, translate it into the equivalent three-digit binary group. For example, 45 base 8 equals 100101 base 2

61 John Owen, Rockport Fulton HS61 Hexadecimal to Binary Converting from Hexadecimal to Binary is the inverse of Binary to Hexadecimal. For each “hex” digit, translate it into the equivalent four-digit binary group. For example, 45 base 16 equals 01000101 base 2

62 John Owen, Rockport Fulton HS62 Octal and Hexadecimal to Binary Exercises Convert each of these to binary: 63 8 123 16 75 8 A2D 16 21 8 3FF 16

63 John Owen, Rockport Fulton HS63 Octal and Hexadecimal to Binary Exercises The answers are: 63 8 = 110011 2 123 16 = 100100011 2 (drop leading 0s) 75 8 = 111101 2 A2D 16 = 110000101101 2 21 8 = 10001 2 3FF 16 = 1111111111 2

64 John Owen, Rockport Fulton HS64 Hexadecimal to Octal Converting from Hexadecimal to Octal is a two-part process. First convert from “hex” to binary, then regroup the bits from groups of four into groups of three. Then convert to an octal number.

65 John Owen, Rockport Fulton HS65 Hexadecimal to Octal For example: 4A3 16 = 0100 1010 0011 2 = 2243 8

66 John Owen, Rockport Fulton HS66 Octal to Hexadecimal Converting from Octal to Hexadecimal is a similar two-part process. First convert from octal to binary, then regroup the bits from groups of three into groups of four. Then convert to an hex number.

67 John Owen, Rockport Fulton HS67 Hexadecimal to Octal For example: 371 8 = 011 111 001 2 = 1111 1001 2 = F9 8

68 John Owen, Rockport Fulton HS68 Octal/Hexadecimal Practice Convert each of these: 63 8 = ________ 16 123 16 = ________ 8 75 8 = ________ 16 A2D 16 = ________ 8 21 8 = ________ 16 3FF 16 = ________ 8

69 John Owen, Rockport Fulton HS69 Octal/Hexadecimal Practice The answers are 63 8 = 33 16 123 16 = 443 8 75 8 = 3D 16 A2D 16 = 5055 8 21 8 = 11 16 3FF 16 = 1777 8

70 John Owen, Rockport Fulton HS70 Part3: Counting, Place Value An introduction to the basic idea of counting in different bases and the place value system, associating it with the familiar base 10 system.

71 John Owen, Rockport Fulton HS71 Review Base Ten Addition, #1 In Base 10 addition, you learned a very simple process. Look at this problem: 12 +37 First add the ones column, then the tens.

72 John Owen, Rockport Fulton HS72 Review Base Ten Addition, #1 12 +37 49 The answer is 49…simple, right?

73 John Owen, Rockport Fulton HS73 Review Base Ten Addition, #2 Now look at this problem: 13 +37 When you add the ones column values, the result of 10 EQUALS the base value of 10, so you have to CARRY a 1.

74 John Owen, Rockport Fulton HS74 Review Base Ten Addition, #2 1 13 +37 0 When a carry is made, you essentially divide by 10 (the base) to determine what value to carry, and mod by 10 to determine what value to leave behind.

75 John Owen, Rockport Fulton HS75 Review Base Ten Addition,#2 1 13 +37 0 3 plus 7 is 10 10 divided by 10 is 1 (carry) 10 mod 10 is 0 (leave)

76 John Owen, Rockport Fulton HS76 Review Base Ten Addition, #2 1 13 +37 50 Answer is 50

77 John Owen, Rockport Fulton HS77 Review Base Ten Addition, #3 Here’s a third example: 16 +37 When you add the ones column values, the result of 13 EXCEEDS the base value of 10, so CARRY a 1.

78 John Owen, Rockport Fulton HS78 Review Base Ten Addition, #3 16 +37 6 plus 7 is 13 13 divided by 10 is 1 (carry) 13 mod 10 is 3 (leave)

79 John Owen, Rockport Fulton HS79 Review Base Ten Addition, #3 1 16 +37 53 Answer is 53

80 John Owen, Rockport Fulton HS80 Review Base Ten Addition, #4 And finally, a fourth example: 76 +35 The ones column result of 11 EXCEEDS the base value of 10, and you CARRY a 1.

81 John Owen, Rockport Fulton HS81 Review Base Ten Addition,#4 1 76 +35 1 6 plus 5 is 11 11 divided by 10 is 1 (carry) 11 mod 10 is 1 (leave)

82 John Owen, Rockport Fulton HS82 Review Base Ten Addition, #4 1 76 +35 1 1+7+3 is 6 plus 5, which equals 11 11 divided by 10 is 1 (carry) 11 mod 10 is 1 (leave)

83 John Owen, Rockport Fulton HS83 Review Base Ten Addition, #4 1 76 +35 111 Answer is 111, base 10

84 John Owen, Rockport Fulton HS84 Base Eight Addition, #1 Now here is an example in base eight: 12 +34 When you add the ones column values, the answer is 6, and the second column answer is 4.

85 John Owen, Rockport Fulton HS85 Base Eight Addition. #1 12 +34 48 Answer is 48, base eight You say, “four eight base eight”, not “forty-eight” The phrase “forty-eight” is meant for base ten only.

86 John Owen, Rockport Fulton HS86 Base Eight Addition, #2 Now look at this problem: 14 +34 When you add the ones column values, the result of 8 EQUALS the base value of 8, and you have to CARRY a one.

87 John Owen, Rockport Fulton HS87 Base Eight Addition, #2 14 +34 Again you divide by 8 (the base) to determine what value to carry, and mod by 8 to determine what value to leave behind.

88 John Owen, Rockport Fulton HS88 Base Eight Addition, #2 1 14 +34 0 4 plus 4 is 8 8 divided by 8 is 1 (carry) 8 mod 8 is 0 (leave)

89 John Owen, Rockport Fulton HS89 Base Eight Addition, #2 1 14 +34 50 Answer is “five zero, base eight”! Looks strange, but it is correct!

90 John Owen, Rockport Fulton HS90 Base Eight Addition, #3 Here’s a third example: 16 +37 When you add the ones column values, the result of 13 EXCEEDS the base value of 8, and you have to CARRY a one.

91 John Owen, Rockport Fulton HS91 Base Eight Addition, #3 1 16 +37 5 6 plus 7 is 13 13 divided by 8 is 1 (carry) 13 mod 8 is 5 (leave)

92 John Owen, Rockport Fulton HS92 Base Eight Addition, #3 1 16 +37 55 Answer is 55, base eight.

93 John Owen, Rockport Fulton HS93 Base Eight Addition, #4 And a fourth example: 76 +35 The ones column result of 11 EXCEEDS the base value of 8, …CARRY a one.

94 John Owen, Rockport Fulton HS94 Base Eight Addition, #4 1 76 +35 3 6 plus 5 is 11 11 divided by 8 is 1 (carry) 11 mod 8 is 3 (leave)

95 John Owen, Rockport Fulton HS95 Base Eight Addition, #4 1 76 +35 33 1+7+3 is 6 plus 5 is 11 11 divided by 8 is 1 (carry) 11 mod 8 is 3 (leave)

96 John Owen, Rockport Fulton HS96 Base Eight Addition, #4 1 76 +35 133 Answer is 133, base 8

97 John Owen, Rockport Fulton HS97 Base Two Addition, #1 Base Two Addition is quite interesting, but also fairly simple. Since the only counting digits in base two are the values 0 and 1, there are only a few situations you have to learn.

98 John Owen, Rockport Fulton HS98 Base Two Addition, #1 We’ll start simple: 1 +1 =10 (“one zero, base two”) This looks strange, but the same process applies.

99 John Owen, Rockport Fulton HS99 Base Two Addition, #1 1 +1 = 10 Since 1 + 1 is 2, this EQUALS the base value of 2, which means you carry the “div” answer and leave the “mod” answer

100 John Owen, Rockport Fulton HS100 Base Two Addition, #1 1 +1 = 10 2 / 2 = 1 (carry) 2 % 2 = 0 (leave) That’s it!

101 John Owen, Rockport Fulton HS101 Base Two Addition, #2 Here’s another: 10 +11 = 101 Can you figure it out?

102 John Owen, Rockport Fulton HS102 Base Two Addition, #2 10 +11 = 101 In the ones column, 1 + 0 is 1. In the second column, 1+1 is 2, or 10 in base 2

103 John Owen, Rockport Fulton HS103 Base Two Addition, #3 And another: 101101 +110011 = Can you figure it out?

104 John Owen, Rockport Fulton HS104 Base Two Addition, #3 Step by step… 1 101101 +110011 = 0

105 John Owen, Rockport Fulton HS105 Base Two Addition, #3 Step by step… 1 101101 +110011 = 00

106 John Owen, Rockport Fulton HS106 Base Two Addition, #3 Step by step… 1 101101 +110011 = 000

107 John Owen, Rockport Fulton HS107 Base Two Addition, #3 Step by step… 1 101101 +110011 = 0000

108 John Owen, Rockport Fulton HS108 Base Two Addition, #3 Step by step… 1 101101 +110011 = 00000 Since 1+1+1 is 3, carry 1 and leave 1

109 John Owen, Rockport Fulton HS109 Base Two Addition, #3 Step by step… 1 101101 +110011 =1100000 All done!

110 John Owen, Rockport Fulton HS110 Base Sixteen, Example #1 In base sixteen, remember the digits are 0-9, then A-F, representing the values 0-15 Here’s an example: 29 +12

111 John Owen, Rockport Fulton HS111 Base Sixteen, Example #1 29 +12 = 3B, base 16 2 + 9 is 11, which is B in base sixteen 2+1 is 3, so the answer is 3B

112 John Owen, Rockport Fulton HS112 Base Sixteen, Example #2 1 A9 +47 = F0, base 16 9+7 is 16, equal to the base, so carry 1 and leave 0 1 + A(10) + 4 is 15, which is F

113 John Owen, Rockport Fulton HS113 Base Sixteen, Example #3 11 D6 +7C = 152, base 16 6+C(12) = 18, carry 1, leave 2 1+D(13)+7 = 21, carry 1, leave 5

114 John Owen, Rockport Fulton HS114 Base Sixteen, Example #4 11 EF +2D = 11C, base 16 F(15) + D(13) = 28, carry 1, leave C(12) 1 + E(14) + 2 = 17, carry 1, leave 1

115 John Owen, Rockport Fulton HS115 Exercises Now try these exercises 1. 1 2 + 1 2 = 2. 7 8 + 6 8 = 3. F 16 + F 16 = 4. 5 8 + 5 8 = 5. 9 16 + B 16 = 6. C 16 + D 16 =

116 John Owen, Rockport Fulton HS116 Exercises 7. 3 8 + 4 8 = 8. F 16 + 2 16 = 9. 10 2 + 10 2 = 10. 1 2 + 1011 2 = 11. 10 2 + 110 2 = 12. 216 8 + 364 8 = 13. 777 8 + 3 8 =

117 John Owen, Rockport Fulton HS117 Exercises 14. ACE 16 + BAD 16 = 15. 234 16 + 975 16 = 16. 42 16 + F 16 + 876 16 =

118 John Owen, Rockport Fulton HS118 ANSWERS (JUMBLED) 7 111210141519 1E100 602BA9 8C71000 10021100167B

119 John Owen, Rockport Fulton HS119 Part 4 In this section you’ll learn how to do subtraction and how to solve simple equations involving Base 2, 8, and 16. Again, it is essentially the same concept as Base 10, just in a different base!

120 John Owen, Rockport Fulton HS120 Review Base Ten Subtraction In Base 10 subtraction, you use a very simple process. Look at this problem: 48 -37 = 11

121 John Owen, Rockport Fulton HS121 Review Base Ten Subtraction 48 -37 = 11 Each column is subtracted to get an answer of 11…

122 John Owen, Rockport Fulton HS122 Subtraction, Base 10 Now look at this problem: 63 -37 In this problem, you need to borrow.

123 John Owen, Rockport Fulton HS123 Subtraction, Base 10 513 63 -37 Borrowing means taking a value from the next column and adding it to the column you need.

124 John Owen, Rockport Fulton HS124 Subtraction, Base 10 513 63 -37 In this case, borrow from the 6, which becomes five, and add 10 to the 3, making 13.

125 John Owen, Rockport Fulton HS125 Subtraction, Base 10 513 63 -37 When you borrow 1 from one column, it becomes the value of the base in the next column, or 10 in this case.

126 John Owen, Rockport Fulton HS126 Subtraction, Base 10 513 63 -37 26 Then you subtract the two columns with a result of 26.

127 John Owen, Rockport Fulton HS127 Subtraction, Base 8 Now let’s try base eight: 63 -37 Again, in this problem, you need to borrow.

128 John Owen, Rockport Fulton HS128 Subtraction, Base 8 511 63 -37 Borrow from the 6, which becomes five, and add 8 to the 3, making 11!

129 John Owen, Rockport Fulton HS129 Subtraction, Base 8 511 63 -37 When you borrow 1 from a column, it becomes the value of the base in the next column, or 8 in this case.

130 John Owen, Rockport Fulton HS130 Subtraction, Base 8 511 63 -37 24 Then you subtract the two columns with a result of 24, base 8.

131 John Owen, Rockport Fulton HS131 Subtraction, Base 16 Now base 16: 519 63 -37 Again, we borrow from the 6, which becomes five, and add 16 to the 3, making 19!

132 John Owen, Rockport Fulton HS132 Subtraction, Base 16 519 63 -37 When you borrow 1 from a column, it becomes the value of the base in the next column, or 16 in this case.

133 John Owen, Rockport Fulton HS133 Subtraction, Base 16 519 63 -37 2C In the ones column, 19 minus 7 is 12, which is C in base sixteen, with 2 in the second column.

134 John Owen, Rockport Fulton HS134 Subtraction, Base 16 Here’s another example in base 16 D6 -3B How is this one solved? Try it.

135 John Owen, Rockport Fulton HS135 Subtraction, Base 16 C22 D6 -3B We must borrow from D, which becomes C, then add 16 to 6, which makes 22.

136 John Owen, Rockport Fulton HS136 Subtraction, Base 16 C22 D6 -3B 9B 22 minus B (11) is B. C minus 3 is 9. Answer is 9B

137 John Owen, Rockport Fulton HS137 Subtraction, Base 2 Now base 2: 11 - 1 10 This one is easy…answer is 10

138 John Owen, Rockport Fulton HS138 Subtraction, Base 2 Another in base 2: 02 110 - 1 Here we need to borrow from the twos place…

139 John Owen, Rockport Fulton HS139 Subtraction, Base 2 02 110 - 1 101 Subtract to get the answer.

140 John Owen, Rockport Fulton HS140 Subtraction, Base 2 Still another in base 2: 02 110 - 11 1 Now borrow again…

141 John Owen, Rockport Fulton HS141 Subtraction, Base 2 2 100 - 11 01 Final answer is 01, base 2

142 John Owen, Rockport Fulton HS142 Simple Equations Here an equation to solve (base 10): x + 6 = 14

143 John Owen, Rockport Fulton HS143 Simple Equations Solution…subtract 6 from both sides x + 6 = 14 -6 -6 x = 8

144 John Owen, Rockport Fulton HS144 Simple Equations Now do it in base 8: x + 6 = 14

145 John Owen, Rockport Fulton HS145 Simple Equations Solution…subtract 6 from both sides x + 6 = 14 -6 -6 x = ?

146 John Owen, Rockport Fulton HS146 Simple Equations Answer is 6, base 8 12 x + 6 = 14 -6 -6 x = 6

147 John Owen, Rockport Fulton HS147 Simple Equations Here’s an equation in base sixteen (remember, A and F are NOT variables, but base sixteen values): x + 2A = F3

148 John Owen, Rockport Fulton HS148 Simple Equations Solution? x + 2A = F3

149 John Owen, Rockport Fulton HS149 Simple Equations Subtract 2A from both sides: E19 x + 2A = F3 - 2A -2A x = C9

150 John Owen, Rockport Fulton HS150 Exercises Now try these exercises 1. 1 2 - 1 2 = 2. 7 8 - 6 8 = 3. F 16 - A 16 = 4. 15 8 - 6 8 = 5. 49 16 - 2B 16 = 6. CC 16 - AD 16 =

151 John Owen, Rockport Fulton HS151 Exercises 7. 73 8 - 34 8 = 8. 3E 16 – 2F 16 = 9. 101 2 - 10 2 = 10. 1101 2 - 11 2 = 11. 1010 2 - 111 2 = 12. 716 8 - 364 8 = 13. 776 8 + 337 8 =

152 John Owen, Rockport Fulton HS152 Exercises Now let’s mix it up a bit! 14. AE 16 + 76 8 = _________ 8 15. 234 8 + 11011011 2 = _________ 16 16. 10110 2 - F 16 + 76 8 = _________ 10 17. 3 8 + 39 10 - 110101 2 = _________ 16 18. 1111 2 - F 16 + 15 10 = _________ 16

153 John Owen, Rockport Fulton HS153 Exercises And finally, some equations 19. x 16 + 76 16 = AB 16 20. x 2 - 1011 2 = 101 2 21. x 8 + 56 8 = 72 8 22. x 2 + 25 10 = 1F 16 23. x 8 + 374 8 - 6556 8 = BAD 16 24. 37 8 + X 16 = 11011110 2

154 John Owen, Rockport Fulton HS154 ANSWERS (JUMBLED) 35 37 69 110 177 332 354 1010 0 1 5 7 11 14 19 1335 10000 14037 1E 1F BF F F

155 155 Representing Fractional Numbers Computers store fractional numbers Negative and positive Storage technique based on floating-point notation Example: 1.345E+5 1.345 = mantissa, E = exponent, + 5 moves decimal IEEE-754 specification Uses binary mantissas and exponents Implementation details are part of advanced study

156 Conversion to Decimal (d n …..d2 d 1 d 0. d -1 d -2 ……) R = ( ) 10

157 Examples

158 Example

159 Part5: Data Representation in Binary Binary values map to two states On or off Bit Each 1 and 0 (on and off ) in a computer Byte Group of 8 bits Word Collection of bytes (typically 4 bytes) Nibble Half a byte or 4 bits Connecting with Computer Science, 2e159

160 Representing Whole Numbers Whole numbers (integer numbers) Stored in fixed number of bits 2010 stored as 16-bit integer 0000011111011010 Equivalent hex value: 07DA Signed numbers stored with twos complement Leftmost bit reserved for sign 1 = negative and 0 = positive If positive: leave as is If negative: perform twos complement Reverse bit pattern and add 1 to number using binary addition 160

161 161 Figure 7-5, Storing numbers in a twos complement 8-bit field Representing Whole Numbers (cont’d.)

162 One’s Complement Way to represent negative values. Change every one in binary to zero and every zero to 1

163 Example Convert (1010011) 2 one’s complement. (0101100) 1’s Convert (1000010011) which is one’s complement to its binary value. (0111101100) 2

164 Two’s complement It is a way to represent a number with both value and sign. The most important property is that the Most Significant Bit has a negative weight. To convert from two’s complement to decimal is an easy way. The only difference is that during computation the weight of the last bit is negative.

165 Example to convert from two’s complement to decimal.

166 Converting from decimal number to two’s complement We have two cases. If it is a positive decimal number. It is the same as normal binary except that you add 0 as MSB to the binary number. If it is negative decimal number. Treat the number as if it is positive. Convert it to binary number. Put Zeroes to the left of the number. Convert the zero to one and one to zero for all digits Add one to the whole number.

167 Subtraction using two’s complement Subtraction process requires two operands: minuend and subtrahend, normally the subtrahend is greater than the minuend. Make sure you have more digits that accommodate the value of the numbers by adding zeros to the left of the two numbers. Convert the subtrahend to two’s complement. Add the two numbers. If the number of digits of the result exceeds numbers of digits both numbers. Cancel that digit.

168 Example of Two’s complement subtraction. Subtract 1001 from 101. Number of digits ( we need 5 digits for those numbers) so, we add trailing zeros Minuend becomes 00101 and the subtrahend becomes 01001 Convert the subtrahend to two’s complement So it 01001 becomes 10111 Add both numbers: 00101 to 10111 00101 +10111 = 11100 As the number of digits of the result is that same as the number of the digits of both number. This is the result. (Note that as the last bit of the result is 1, it means the number is negative, to find its value. Follow the rules to convert from two’s complement to decimal)

169 Example of Two’s complement subtraction. Subtract 110 from 1011. Number of digits ( we need 5 digits for those numbers) so, we add trailing zeros Minuend becomes 01011 and the subtrahend becomes 00110 Convert the subtrahend to two’s complement So it 00110 becomes 11010 Add both numbers: 01011 to 11010 01011+ 11010 = 100101 Because we have six digits, the left most digits is discarded and keep the number of the digits to 5. the result will b 00101 (Note that as the last bit of the result is 0, it means the number is positive, to find its value. Follow the rules to convert from two’s complement to decimal)

170 John Owen, Rockport Fulton HS170 Exercises 1-5 Convert each of these to base 2 1. 52 8 2. 273 8 3. 617 8 4. 4472 8 5. 3502 8

171 John Owen, Rockport Fulton HS171 Exercises 6 - 10 Convert each of these to base 2 6. 673 16 7. 2A5 16 8. DEB 16 9. 50C 16 10. 2937 16

172 John Owen, Rockport Fulton HS172 Exercises 11 - 15 Convert each of these to base 2 11. 45 10 12. 36 10 13. 17 10 14. 72 10 15. 57 10

173 John Owen, Rockport Fulton HS173 Exercises 16 - 20 Convert each of these to base 8 16. 110011 2 17. 1111001 2 18. 10010110 2 19. 11011011 2 20. 110100101 2

174 John Owen, Rockport Fulton HS174 Exercises 21 - 25 Convert each of these to base 8 21. 453 16 22. D10 16 23. 729 16 24. BCEF 16 25. 4A6 16

175 John Owen, Rockport Fulton HS175 Exercises 26 - 30 Convert each of these to base 8 26. 46 10 27. 89 10 28. 70 10 29. 120 10 30. 273 10

176 John Owen, Rockport Fulton HS176 Exercises 31 - 35 Convert each of these to base 16 31. 101101 2 32. 1110001 2 33. 11001101 2 34. 1000100101 2 35. 1100001001 2

177 John Owen, Rockport Fulton HS177 Exercises 36 - 40 Convert each of these to base 16 36. 46 8 37. 276 8 38. 725 8 39. 5624 8 40. 7013 8

178 John Owen, Rockport Fulton HS178 Exercises 41 - 45 Convert each of these to base 16 41. 74 10 42. 156 10 43. 168 10 44. 415 10 45. 550 10

179 John Owen, Rockport Fulton HS179 ANSWERS…JUMBLED! 26 56 63 71 106 131 170 171 225 6420 10001 100100 101010 101101 111001 136357 10010000 10111011 226 309 333 421 645 2123 2246 3451 110001111 1010100101 10100001100 11001110011 11101000010 100100111010 110111101011 10100100110111 19F 1D5 2D 4A 9C A8 B94 BE CD EOB


Download ppt "Computer Science Introduction to the Number Base Unit Adapted from Slides by John Owen Computer Science Instructor, Rockport-Fulton High School, Rockport,"

Similar presentations


Ads by Google