Chapter 7 Lab - Decimal, Binary, Octal, Hexadecimal Numbering Systems This assignment is designed to familiarize you with different numbering systems, specifically: binary, octal, hexadecimal (and decimal) and converting between them. This lab can be printed out directly or downloaded and printed. Click here for a printable PDF version of the lab. You can write your responses directly on the printed sheet. To print this sheet directly: make sure you have a printer available on your machine or network. In the browser, drag down the File menu and click on print. To download, drag down your browser s File menu and select Save as Then save the file with whatever name you wish to your machine. You can then print the file. Note on formatting used below: x 2 ^ 2 equals times 2 raised to 2. The notation *2**2 is the same thing. You might see this in a computer language. In the spirit of being well-rounded both will be used here. First, a quick review of how to do number conversions. Decimal: base ( 2 3 4 5 6 7 8 9) Binary: base 2 ( ) Octal: base 8 ( 2 3 4 5 6 7) Hexadecimal: base 6 ( 2 3 4 5 6 7 8 9 A B C D E F) Our handy basic number conversion table: Base base 2 base 8 base 6 Decimal binary octal hex(adecimal) 2 2 2 (base 2 is at 2 digits already) 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 (base 8 just went to 2 digits) 9 9 ------------------------------------------------------------ (base goes to two digits) 2 A 3 B 2 4 C 3 5 D 4 6 E 5 7 F (beyond this base 6 goes to 2 digits) Let s look at the value of digit at PLACE given the four numbering systems:
POWER (place) 4 3 2 Base Base 2 6 8 4 2 Base 8 496 52 64 8 Base 6 65536 496 256 6 For example: POWER (place) 4 3 2 Final result in Decimal Base of Base 2 of Base 8 of Base 6 o x ^ 4, x 2 ^ 4 6 x 8 ^ 4 496 x 6 ^ 4 65536 x ^ 3 x 2 ^ 3 x 8 ^ 3 x 6 ^ 3 x ^ 2 x 2 ^ 2 x 8 ^ 2 x 6 ^ 2 x ^ x 2 ^ x 8 ^ x 6 ^ x ^ x x 2 ^ x x 8 ^ x x 6 ^ x + + + + 6 + + + + 7 496 + + + + 497 65536 + + + + 65537 Going from binary/octal/hexadecimal to decimal: An easy way to remember it: take the number and raise the base to the place binary to decimal example *2**2 + *2** + *2** 4 + + 5 That s times the base (of 2) raised to the place (2) PLUS times the base (again, 2) raised to the place () PLUS times the base (still 2) raised to the place () octal to decimal example 5 *8** + 5*8** 8 + 5 3 That s times the base (of 8) raised to the place () PLUS 5 times the base (again, 8) raised to the place () hex to decimal examples *6** + *6** 6
That s times the base (of 6) raised to the place () PLUS times the base (yup, 6) raised to the place (). A *6** + *6** 26 That s times the base (of 6) raised to the place () PLUS (A is in decimal) times the base (of 6) raised to the place (). With hex you have to remember what the decimal equivalent of the numbers are using our handy chart above. Going from Decimal to Binary (and octal and hex) One way is to work with the remainder continually dividing the initial number and then resulting numbers by the base until it cannot be divided without fractions. Then take the remainders, beginning with the first one produced, and write them out from right to left. Example of decimal to binary: Take the decimal number to convert to binary. The decimal number is divided by the base (2) to find the quotient and remainder. The number / 2 5 with remainder of The number 5 / 2 25 with remainder of The number 25 / 2 2 with remainder of The number 2 / 2 6 with remainder of The number 6 / 2 3 with remainder of The number 3 / 2 with remainder of The number / 2 with remainder of Now from the top take the remainders and write from right to left (or from the bottom up and write left to right). That gives us the binary number: Example of decimal to octal: Take the decimal number to convert to octal. The decimal number is divided by the base (8) to find the quotient and remainder. The number / 8 2 with remainder of 4 The number 2 / 8 with remainder of 4 The number / 8 with remainder of Now from the top take the remainders and write right to left. That gives us the octal number: 44 Another easy way for smaller numbers is using the place table. We know for each place in base 2 we are multiplying by two. We have: PLACE 6 5 4 3 2
Decimal Equivalent if present Total of all these numbers added together 27 Binary equivalent (a 6 digit binary number) 64 32 6 8 4 2 64 32 6 8 4 2 So, for example, how would you represent 45 decimal in binary? PLACE 6 5 4 3 2 Decimal 64 32 6 8 4 2 Equivalent if present 45 these 32 8 4 numbers added together Binary equivalent, Binary: So, ever wonder why everything in computers is 6, 32, 64, 28, 256, 52, etc? Now it should be making a lot more sense. The computer, of course, is using binary numbers. Going from binary to octal/hex and back (recall our basic conversion table) Base base 2 base 8 base 6 Decimal binary octal hex(adecimal) 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 9 9 ----------------------------------------------------------------- 2 A 3 B
2 4 C 3 5 D 4 6 E 5 7 F Octal is every three bits starting from right-most digit. Example: (grouping the digits three at a time from the right-most digit) NOW, simply find the octal value for each grouping of three in order from left and that is the final result BINARY OCTAL 2 2 3 223 you can do the same thing going backwards to binary. Hex works the same way. But, it is every 4 bits starting from right-most digit. Example: BINARY OCTAL 9 3 93 Questions Ok, time for you to do a little work. Use the number conversion program to check your answers. You must show your work.. Take the following decimal numbers and convert them to binary, octal and hexadecimal: 2 35 27 245 768 2. Take the following binary numbers and convert to octal, hex, and decimal: 3. Take the following octal numbers and convert to binary and hex: 77
35 2 467 4. Take the following hex numbers and convert to binary and octal: F FE A23 AB2C3