Name: ____________ Computer Number Systems Packet Number Systems are used to express numbers using digits or symbols. Most number systems are fairly straight forward. But there are a couple, like the Roman Numerals that can a bit more complex. Understanding how they work and how they relate to each other is important for computers. This is because computers work using the binary number system since a zero and a one can be easily represented using ground and positive voltage. There are others like octal and hexadecimal that are also used frequently. The key aspect of the number systems that we will look at is the base. The base indicates the number of digits for each place. The one that we use is base 10 (decimal). The 10 digits that we use in this are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Why do we use this over something else like base 8?..... It is for no other reason than the fact that we are born with 10 fingers and that is what all humans learn to count with. Names Most number systems can be referred to using their base like base 5, base 7, and base 9. Some are so common that they are referred to using their actual name. They are: base 2 – binary base 8 – octal base 10 – decimal base 16 – hexadecimal When we write out the numbers, we can indicate what base they are in by using a subscript. (Example – 359010) Counting Counting in the systems that we will look at will all function the same way for each one. You already learned counting in the decimal number system in elementary school. Lets review! We will start counting with our first digit which is 0. Then we run through all our other digits from 1 all the way to 9. Then when we run out of digits, we change the 9 back to our first digit 0. But at the same time we add a 1 to the next position. As we progress to 9 each position, it will revert to 0 and a 1 is added to the next position. So a 9,999 will transition to 10,000 as each 9 goes to 0 and 1 gets added to the next position. The other thing to keep in mind is that the last digit in each set is one less than the base. So octal, which is base 8, has digits 0, 1, 2, 3, 4, 5, 6, 7. Notice that, since we start counting at 0, that gives us a total of 8 digits. Hexadecimal Hexadecimal has 16 digits but we only are familiar with 10. So we use the letters A through F to replace the numbers 10 through 15. Why? For no other reason other than we are familiar with those symbols and they are already on a standard keyboard. Page 1 Counting Chart Decimal Octal Binary Hexadecimal Base 5 Base 6 Base 9 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Page 2 Adding Numbers Adding again works that same way that it did in elementary school. We add the numbers in each position and if the sum goes over the base, we subtract the base and carry a 1 to the next position. When we add 48 with 78, we first add the 8 with 8 and get a 16. The 6 (16-10) stays at the ones place and we add a 1 to the tens place. For the tens place we add 1 + 4 + 7 and get a 12. We leave the 2 (12-10) and carry a 1. So the result will be 126. Examples 111 1 11101102 + 1101002 10101010 1 11 517418 +326548 104615 1 1 CA97116 +E295416 1AD2C5 1st : 0 + 0 = 0 2nd : 1 + 0 = 1 3rd : 1 + 1 = 2 → 2 - 2 = 0, carry 1 4th : 1 + 0 + 0 = 1 5th : 1 + 1 = 2 → 2 - 2 = 0, carry 1 6th : 1 + 1 + 1 = 3 → 3 - 2 = 1, carry 1 7th : 1 + 1 = 2 → 2 - 2 = 0, carry 1 8th : 1 1st : 1 + 4 = 5 2nd : 4 + 5 = 9 → 9 - 8 = 1, carry 1 3rd : 1 + 7 + 6 = 14 → 14 - 8 = 6, carry 1 4th : 1 + 1 + 2 = 4 5th : 5 + 3 = 8 → 8 - 8 = 0, carry 1 6th : 1 1st : 1 + 4 = 5 2nd : 7 + 5 = 12(C) 3rd : 9 + 9 = 18 → 18 - 16 = 2, carry 1 4th : 1 + 10(A) + 2 = 13(D) 5th : 12(C) + 14(E) = 26 → 26 - 16 = 10(A), carry 1 6th : 1 Adding Binary Numbers 102 + 12 1012 + 12 1012 + 1102 10102 + 1112 10112 + 111012 101112 + 10012 1010112 + 1110102 101110102 + 111111012 1101102 + 1010112 1110112 + 1001112 10101112 + 10101102 111111112 + 111111112 Page 3 Adding Numbers in Different Bases 7528 +5538 1023 +1113 4025 +3115 1678 +4178 2123 +1203 2045 +3415 75216 +55316 65B16 +AA316 E3A16 +85B16 4559 +5839 3234 +1114 1536 +5436 1057 +6157 181010 +921510 7248 +1578 Page 4 Converting Numbers to Decimal Equivalents A number in base b can be converted to its equivalent in base 10 by using place values. Place Value Formula b8 b 7 b 6 b5 b 4 b3b 2 b1b 0 .b 1b 2 b 3b 4 Given 1394210, what do the individual digits represent? 13942 10 = 1(10)4 + 3(10)3 + 9(10)2 + 4(10)1 + 2(10)0 = 10,000 + 3000 + 900 + 40 +2 Likewise, the digits in the base 2 number 110101 represent powers of the base 2. 110101 2 = 1(2)5 + 1(2)4 + 0(2)3 + 1(2)2 + 0(2)1 + 1(2)0 = 1(32) + 1(16) + 0(8) + 1(4) + 0(2) + 1(1) = 32 + 16 + 0 + 4 +0 +1 = 5310 The same can be done for any other base such as converting 13F16 to base ten. 13F16 = 1(16)2 + 3(16)1 + F(16)0 = 1(256) + 3(16) + 15(1) = 256 + 48 + 15 = 319 10 Or to converting 3758 to base ten. 3758 = 3(8)2 + 7(8)1 + 5(8)0 = 3(64) + 7(8) + 5(1) = 192 + 56 +5 = 253 10 Page 5 Converting Numbers to Decimal Equivalents Practice 1012 = 10102 = 1011012 = 1101010.112 = 2716 = 13AD16 = 34178 = 110213 = Page 6 Converting from Binary to Hexadecimal Converting back and forth from binary to hexadecimal is straight forward. This is because 4 binary digits matches exactly with one hexadecimal digit. To covert from decimal to hexadecimal, just look up each hexadecimal digit and write out the equivalent set four binary digits. To go the other way, circle groups of four binary digits and write out the equivalent hexadecimal digit. This should be done from right to left and fill in any leading zero’s 0 1 2 3 4 5 6 7 8 9 A B C D E F 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Example 1: 8 1000 Example 2: 0100 4 8D316 = ? 2 D 1101 100010111002 = 3 0111 ? 0101 5 16 1100 C Converting from Binary to Hexadecimal Practice 1011011011101100010110112 1000111010111101011101100100101001012 A7F316 D239AE16 Page 7 Converting from Decimal to other Bases One way to do this is to repeatedly divide the decimal number by the base in which it is to be converted, until the quotient becomes zero. As the number is divided, the remainders - in reverse order - form the digits of the number in the other base. This is also referred to as the divide and conquer algorithm. Examples 173410 → 110110001102 0 _ R _1 2 1 _ R _1 2 3_R_0 2 6 _ R _1 2 13 _ R _1 173410 → 6C616 0_ R_6 16 6 _ R _12 16 108 _ R _ 6 16 1734 173410 → 33068 0_ R_3 8 3_ R_3 8 27 _ R _ 0 8 216 _ R _ 6 8 1734 2 27 _ R _ 0 2 54 _ R _ 0 2 108 _ R _ 0 2 216 _ R _1 2 433 _ R _1 2 867 _ R _ 0 2 1734 Some things to note: The remainders go in reverse order. So the remainder left at the end is the most significant digit. And the first remainder that you obtained is the least significant digit. When we got a remainder of 12 for hexadecimal, we put a C when we wrote out our hexadecimal number. Page 8 Converting from Decimal to BaseX Practice 4710 =___________2 27410 =___________2 771210 = ___________2 4542510 =___________2 Page 9 4710 =___________8 27410 =___________8 771210 = ___________16 4542510 =___________16 771210 =___________16 4542510 =___________16 Page 10 Page 11