Computer Science LESSON 2 ON Number Bases John
Computer Science LESSON 2 ON Number Bases John Owen, Rockport Fulton HS 1
Objective n In the last lesson you learned about different Number Bases used by the computer, which were n Base Two – binary n Base Eight – octal n Base Sixteen – hexadecimal John Owen, Rockport Fulton HS 2
Base Conversion n You also learned how to convert from the decimal (base ten) system to each of the new bases…binary, octal, and hexadecimal. John Owen, Rockport Fulton HS 3
Other conversions n Now you will learn other conversions among these four number systems, specifically: Binary to Decimal n Octal to Decimal n Hexadecimal to Decimal n John Owen, Rockport Fulton HS 4
Other conversions n As well as Binary to Octal n Octal to Binary n Binary to Hexadecimal n Hexadecimal to Binary n John Owen, Rockport Fulton HS 5
Other conversions n And finally Octal to Hexadecimal n Hexadecimal to Octal n John Owen, Rockport Fulton HS 6
Binary to Decimal Each binary digit in a binary number has a place value. n 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. n Technically this is the 20 place. n John Owen, Rockport Fulton HS 7
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. n Technically this is the 21 place. n In base ten, this would be the “tens” place and would be worth 10. n John Owen, Rockport Fulton HS 8
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. n Technically this is the 22 place. n In base ten, this would be the “hundreds” place and would be worth 100. n John Owen, Rockport Fulton HS 9
Binary to Decimal The total value of this binary number, 111, is 4+2+1, or seven. n In base ten, 111 would be worth 100 + 1, or one-hundred eleven. n John Owen, Rockport Fulton HS 10
Binary to Decimal n Can you figure the decimal values for these binary values? 11 n 101 n 110 n 1111 n 11011 n John Owen, Rockport Fulton HS 11
Binary to Decimal n Here are the answers: 11 is 3 in base ten n 101 is 5 n 110 is 6 n 1111 is 15 n 11011 is 27 n John Owen, Rockport Fulton HS 12
Octal to Decimal Octal digits have place values based on the value 8. n In the number 111, base 8, the digit farthest to the right is in the “ones” place and is worth 1. n Technically this is the 80 place. n John Owen, Rockport Fulton HS 13
Octal to Decimal The 2 nd digit from the right, 111, is in the “eights” place, the “base” place, and is worth 8. n Technically this is the 81 place. n John Owen, Rockport Fulton HS 14
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. n Technically this is the 82 place. n John Owen, Rockport Fulton HS 15
Octal to Decimal n The total value of this octal number, 111, is 64+8+1, or seventy-three. John Owen, Rockport Fulton HS 16
Octal to Decimal n Can you figure the value for these octal values? 21 n 156 n 270 n 1164 n 2105 n John Owen, Rockport Fulton HS 17
Octal to Decimal n Here are the answers: 21 is 17 in base 10 n 156 is 110 n 270 is 184 n 1164 is 628 n 2105 is 1093 n John Owen, Rockport Fulton HS 18
Hexadecimal to Decimal Hexadecimal digits have place values base on the value 16. n In the number 111, base 16, the digit farthest to the right is in the “ones” place and is worth 1. n Technically this is the 160 place. n John Owen, Rockport Fulton HS 19
Hexadecimal to Decimal The 2 nd digit from the right, 111, is in the “sixteens” place, the “base” place, and is worth 16. n Technically this is the 161 place. n John Owen, Rockport Fulton HS 20
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. n Technically this is the 162 place. n John Owen, Rockport Fulton HS 21
Hexadecimal to Decimal n The total value of this hexadecimal number, 111, is 256+16+1, or two hundred seventy-three. John Owen, Rockport Fulton HS 22
Hexadecimal to Decimal n Can you figure the value for these hexadecimal values? 2 A n 15 F n A 7 C n 11 BE n A 10 D n John Owen, Rockport Fulton HS 23
Hexadecimal to Decimal n Here are the answers: 2 A is 42 in base 10 n 15 F is 351 n A 7 C is 2684 n 11 BE is 4542 n A 10 D is 41229 n John Owen, Rockport Fulton HS 24
Binary to Octal The conversion between binary and octal is quite simple. n Since 2 to the power of 3 equals 8, it takes 3 base 2 digits to combine to make a base 8 digit. n John Owen, Rockport Fulton HS 25
Binary to Octal n n n n 000 base 2 equals 0 base 8 0012 = 18 0102 = 28 0112 = 38 1002 = 48 1012 = 58 1102 = 68 1112 = 78 John Owen, Rockport Fulton HS 26
Binary to Octal What if you have more than three binary digits, like 110011? n Just separate the digits into groups of three from the right, then convert each group into the corresponding base 8 digit. n 110 011 base 2 = 63 base 8 n John Owen, Rockport Fulton HS 27
Binary to Octal n Try these: 111100 n 100101 n 111001 n 1100101 n n Hint: when the leftmost group has fewer than three digits, fill with zeroes from the left: 1100101 = 1 100 101 = 001 100 101 110011101 John Owen, Rockport Fulton HS 28
Binary to Octal n The answers are: 1111002 = 748 n 1001012 = 458 n 1110012 = 718 n 11001012 = 1458 n 1100111012 = 6358 n John Owen, Rockport Fulton HS 29
Binary to Hexadecimal The conversion between binary and hexadecimal is equally simple. n Since 2 to the power of 4 equals 16, it takes 4 base 2 digits to combine to make a base 16 digit. n John Owen, Rockport Fulton HS 30
Binary to Hexadecimal n n n n 0000 base 2 equals 0 base 8 00012 = 116 00102 = 216 00112 = 316 01002 = 416 01012 = 516 01102 = 616 01112 = 716 John Owen, Rockport Fulton HS 31
Binary to Hexadecimal n n n n 10002 10012 10102 10112 11002 11012 11102 11112 = = = = 816 916 A 16 B 16 C 16 D 16 E 16 F 16 John Owen, Rockport Fulton HS 32
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. n 1101 0111 base 2 = D 7 base 16 n John Owen, Rockport Fulton HS 33
Binary to Hexadecimal n Try these: 11011100 n 10110101 n 1001 n 110110101 n n Hint: when the leftmost group has fewer than four digits, fill with zeroes on the left: 110110101 = 1 1011 0101 = 0001 1011 0101 1101001011101 John Owen, Rockport Fulton HS 34
Binary to Hexadecimal n The answers are: 110111002 = DC 16 n 101101012 = B 516 n 10012 = 9916 n 1101101012 = 1 B 516 n 1 1010 0101 11012 = 1 A 5 D 16 n John Owen, Rockport Fulton HS 35
Octal to Binary Converting from Octal to Binary is just the inverse of Binary to Octal. n For each octal digit, translate it into the equivalent three-digit binary group. n For example, 45 base 8 equals 100101 base 2 n John Owen, Rockport Fulton HS 36
Hexadecimal to Binary Converting from Hexadecimal to Binary is the inverse of Binary to Hexadecimal. n For each “hex” digit, translate it into the equivalent four-digit binary group. n For example, 45 base 16 equals 01000101 base 2 n John Owen, Rockport Fulton HS 37
Octal and Hexadecimal to Binary Exercises n Convert each of these to binary: 638 n 12316 n 758 n A 2 D 16 n 218 n 3 FF 16 n John Owen, Rockport Fulton HS 38
Octal and Hexadecimal to Binary Exercises n The answers are: 638 = 1100112 n 12316 = 1001000112 (drop leading 0 s) n 758 = 1111012 n A 2 D 16 = 1100001011012 n 218 = 100012 n 3 FF 16 = 111112 n John Owen, Rockport Fulton HS 39
Hexadecimal to Octal Converting from Hexadecimal to Octal is a two-part process. n First convert from “hex” to binary, then regroup the bits from groups of four into groups of three. n Then convert to an octal number. n John Owen, Rockport Fulton HS 40
Hexadecimal to Octal n For example: 4 A 316 n = 0100 1010 00112 n = 010 100 0112 n = 22438 n John Owen, Rockport Fulton HS 41
Octal to Hexadecimal Converting from Octal to Hexadecimal is a similar two-part process. n First convert from octal to binary, then regroup the bits from groups of three into groups of four. n Then convert to an hex number. n John Owen, Rockport Fulton HS 42
Hexadecimal to Octal n For example: 3718 n = 011 111 0012 n = 1111 10012 n = F 98 n John Owen, Rockport Fulton HS 43
Octal/Hexadecimal Practice n Convert each of these: 638 = ____16 n 12316 = ____8 n 758 = ____16 n A 2 D 16 = ____8 n 218 = ____16 n 3 FF 16 = ____8 n John Owen, Rockport Fulton HS 44
Octal/Hexadecimal Practice n The answers are 638 = 3316 n 12316 = 4438 n 758 = 3 D 16 n A 2 D 16 = 50558 n 218 = 1116 n 3 FF 16 = 17778 n John Owen, Rockport Fulton HS 45
Number Base Conversion Summary Now you know twelve different number base conversions among the four different bases (2, 8, 10, and 16) n With practice you will be able to do these quickly and accurately, to the point of doing many of them in your head! n John Owen, Rockport Fulton HS 46
Practice Now it is time to practice. n Go to the Number Base Exercises slide show to find some excellent practice problems. n Good luck and have fun! n John Owen, Rockport Fulton HS 47
- Slides: 47