Conversion tutorial follows the conversion chart...
| CNS Number System Conversions - Binary - Octal - Hexadecimal | |||||||||
| The
key is understanding powers of 2, 8, and 16! Note the relationships below in
number of zeros and the corresponding powers. -- Cool! Corresponding decimal
numbers are the "magic" numbers for computers (now you know why)!
E.g., what is the highest decimal number that can be expressed in 8 binary
bits? -- 11111111 = 255 decimal, 377 octal, and FF hexadecimal -- add 1 to
each and you get 100000000 (2 to the 8th power in decimal), 256 decimal, 400
octal, and 100 hexadecimal (16 to the 2nd power or 16x16 in decimal). Also
remember that every numbering system begins with 0! And 0-255 decimal is
actually 256 numbers! The A-F in hexadecimal are numbers not letters! We
could just as easily have made up other number symbols to represent those
extra 6 numbers between 9 and 10 in hexadecimal. Need help? E-mail Tere Prasse. |
|||||||||
| Decimal | Binary | Power of 2 | Octal | Power of 8 | Hexadecimal | Power of 16 |
|
Decimal | Hex |
| 0 | 0 | 0 | 0 | 0 | 0 | ||||
| 1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | |
| 2 | 10 | 1 | 2 | 2 | 2 | 2 | |||
| 4 | 100 | 2 | 4 | 4 | 3 | 3 | |||
| 8 | 1000 | 3 | 10 | 1 | 8 | 4 | 4 | ||
| 16 | 10000 | 4 | 20 | 10 | 1 | 5 | 5 | ||
| 32 | 100000 | 5 | 40 | 20 | 6 | 6 | |||
| 64 | 1000000 | 6 | 100 | 2 | 40 | 7 | 7 | ||
| 128 | 10000000 | 7 | 200 | 80 | 8 | 8 | |||
| 256 | 100000000 | 8 | 400 | 100 | 2 | 9 | 9 | ||
| 512 | 1000000000 | 9 | 1000 | 3 | 200 | 10 | A | ||
| 1024 | 10000000000 | 10 | 2000 | 400 | 11 | B | |||
| 2048 | 100000000000 | 11 | 4000 | 800 | 12 | C | |||
| 4096 | 1000000000000 | 12 | 10000 | 4 | 1000 | 3 | 13 | D | |
| 8192 | 10000000000000 | 13 | 20000 | 2000 | 14 | E | |||
| 16384 | 100000000000000 | 14 | 40000 | 4000 | 15 | F | |||
| 32768 | 1000000000000000 | 15 | 100000 | 5 | 8000 | 16 | 10 | ||
| 65536 | 10000000000000000 | 16 | 200000 | 10000 | 4 | ||||
| 131072 | 100000000000000000 | 17 | 400000 | 20000 | |||||
| 262144 | 1000000000000000000 | 18 | 1000000 | 6 | 40000 | ||||
| 524288 | 10000000000000000000 | 19 | 2000000 | 80000 | |||||
| 1048576 | 1E+020 | 20 | 4000000 | 100000 | 5 | ||||
| 2097152 | 1E+021 | 21 | 10000000 | 7 | 200000 | ||||
| 4194304 | 1E+022 | 22 | 20000000 | 400000 | |||||
| 8388608 | 1E+023 | 23 | 40000000 | 800000 | |||||
| 16777216 | 1E+024 | 24 | 100000000 | 8 | 1000000 | 6 | |||
| 33554432 | 1E+025 | 25 | 200000000 | 2000000 | |||||
| 67108864 | 1E+026 | 26 | 400000000 | 4000000 | |||||
| 134217728 | 1E+027 | 27 | 1000000000 | 9 | 8000000 | ||||
| 268435456 | 1E+028 | 28 | 2000000000 | 10000000 | 7 | ||||
| 536870912 | 1E+029 | 29 | 4000000000 | 20000000 | |||||
| 1073741824 | 1E+030 | 30 | 10000000000 | 10 | 40000000 | ||||
Let's use binary 11111111 (8 "on" bits). Start at the left and note the leftmost number by itself is 10000000 or 2 to the seventh (128). Take each digit in turn; the next is 1000000 or 2 to the sixth (64); etc. If we do this by writing down each decimal equivalent and then adding them, we get the decimal number.
128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255
Let's take another example. How about 10010110...
128 + 0 + 0 + 16 + 0 + 4 + 2 + 0 = 150
Notice if the binary digit is zero, it becomes a zero in our little equation. These are so easy you can do them in your head!
Octal to Decimal
Also easy, once you get the hang of it! Let's try 377 in octal. Again, start at the leftmost digit by itself, which is 300 which is the same thing as 192 in decimal (64 decimal or 8 to the 2nd -- see the 2 zeros -- times the 3 = 192), then 70 which is the same as 56 in decimal (8 decimal or 8 to the 1st -- see the 1 zero -- times the 7 = 56), the 7 which is also 7 in decimal (1 or 8 to the zero power times 7 = 7). Check the powers of 8 in the chart above to get the picture.
192 + 56 + 7 = 255
How about another? Try octal 226...
200 or 2 x 64 = 128 --then-- 20 or 2 x 8 = 16 --then-- 6 or 6 x 1 = 6
128 + 16 + 6 = 150
Hexadecimal to Decimal
Let's take a look at FF in hexadecimal. Using the same technique, we take F0 first which is 16 to the 1st (16) times F (15 in decimal) = 240, and then 16 to the 0 power (1) times F (15 in decimal) = 15. This is a piece of cake!
240 + 15 = 255
Another? Give 96 in hexadecimal a try...
90 or 9 x 16 = 144 --then-- 6 or 6 x 1 = 6
144 + 6 = 150
One more? Try AD in hexadecimal...
A0 or 10 x 16 = 160 --then-- D or 13 x 1 = 13
160 + 13 = 173
If you practice with these enough, you will soon be able to do all the easier numbers (256 decimal and below) quickly in your head.
Notice in all the conversions above we were multiplying and then adding (in binary, we were actually multiplying by 1 for each digit); to convert the other way, we divide by the highest power that can be divided and then subtract (it's a remainder). Let's take a look at a few.
Decimal to Binary
Let's try our favorite, 255 in decimal. Since we're dealing with 1s and 0s in binary, we can dispense with the division and go straight to subtraction. Start with the highest power of 2 which when subtracted gives a positive result. So in this case, we start with 2 to the 7th or 128 in decimal. Then try each lesser power of 2 -- if it gives a negative, we can't subtract it, so it would be a zero. But in our example below, every one of the powers subtracts.
255 - 128 = 127 - 64 = 63 - 32 = 31 - 16 = 15 - 8 = 7 - 4 = 3 - 2 = 1
| 128 | = | 10000000 | (2 to 7th) |
| 64 | = | 1000000 | (2 to 6th) |
| 32 | = | 100000 | (2 to 5th) |
| 16 | = | 10000 | (2 to 4th) |
| 8 | = | 1000 | (2 to 3rd) |
| 4 | = | 100 | (2 to 2nd) |
| 2 | = | 10 | (2 to 1st) |
| 1 | = | 1 | (2 to zero) |
| 255 | = | 11111111 |
Another? Let's take the old 150 decimal we used above to compare with how it plays out...
150 - 128 = 22 - 0 = 22 - 0 = 22 - 16 = 6 - 0 = 6 - 4 = 2 - 2 = 0
Notice we can't subtract 2 to the 6th, 5th, 3rd or 0 powers so we put a zero placeholder simply for logic purposes in this example.
| 128 | = | 10000000 | (2 to 7th) |
| 0 | = | 0000000 | |
| 0 | = | 000000 | |
| 16 | = | 10000 | (2 to 4th) |
| 0 | = | 0000 | |
| 4 | = | 100 | (2 to 2nd) |
| 2 | = | 10 | (2 to 1st) |
| 0 | = | 0 | |
| 150 | = | 10010110 |
Decimal to Octal
Here we go with 255 decimal again... Start with the highest power of 8 that can be divided into 255. It's 8 to the 2nd or 64. 64 goes into 255 3 times with 63 left over. Then take the next power of 8 (8 to the 1st or 8) that can be divided into the remainder. 8 goes into 63 7 times with 7 left over. For illustration logic, we can now take 8 to the 0 power or 1 and divide that into the remainder which gives us 7.
255 / 64 = 3 with remainder 63 --then-- 63 / 8 = 7 with remainder 7
| 192 | = | 300 | (8 to 2nd in octal times 3) |
| 56 | = | 70 | (8 to 1st in octal times 7) |
| 7 | = | 7 | (8 to 0 in octal times 7) |
| 255 | = | 377 |
Now for our second try... 150 in decimal...
150 / 64 = 2 with remainder 22 --then-- 22 / 8 = 2 with remainder 6
| 128 | = | 200 | (8 to 2nd in octal times 2) |
| 16 | = | 20 | (8 to 1st in octal times 2) |
| 6 | = | 6 | (8 to 0 in octal times 6) |
| 150 | = | 226 |
By now you should have noticed the easy shortcut. Just flow out every division result from left to right and you get the octal number.
Decimal to Hexadecimal
Like falling off a log... We use exactly the same logic but divide by powers of 16. We'll start with the good old 255 in decimal. Remember to think of A-F in hexadecimal as numbers!
255 / 16 = 15 (hexadecimal F) remainder 15 (hexadecimal F)
| 240 | = | F0 | (16 to 1st in hex times F) |
| 15 | = | F | (16 to 0 in hex times F) |
| 255 | = | FF |
Try our 150 in decimal...
150 / 16 = 9 remainder 6
| 144 | = | 90 | (16 to 1st in hex times 9) |
| 6 | = | 6 | (16 to 0 in hex times 6) |
| 150 | = | 96 |
Let's go for one more... 173 in decimal.
173 / 16 = 10 (A in hexadecimal) remainder 13 (D in hexadecimal)
| 160 | = | A0 | (16 to 1st in hex times A) |
| 13 | = | D | (16 to 0 in hex times D) |
| 173 | = | AD |
Here's one for a little challenge... 3028 in decimal. (Start with 16 to 2nd.)
3028 / 256 = 11 (B in hexadecimal) remainder 212 -- then--
212 / 16 = 13 (D in hexadecimal) remainder 4
| 2816 | = | B00 | (16 to 2nd in hex times B) |
| 208 | = | D0 | (16 to 1st in hex times D) |
| 4 | = | 4 | (16 to 0 in hex times 4) |
| 3028 | = | BD4 |
Try 4100 in decimal for a little trickiness... (Start with 16 to 3rd.)
4100 / 4096 = 1 remainder 4 --then--
4 / 256 = 0 remainder 4 --then--
4 / 16 = 0 remainder 4
| 4096 | = | 1000 | (16 to 3rd in hex times 1) |
| 0 | = | 000 | (16 to 2nd in hex times 0) |
| 0 | = | 00 | (16 to 1st in hex times 0) |
| 4 | = | 4 | (16 to 0 in hex times 4) |
| 4100 | = | 1004 |
Now go practice, practice, practice!!! You have the power (of 2, 8, and 16)! :)
Download Lotus 1-2-3 Millennium Decimal - Binary - Octal - Hexadecimal
Converter
(May be used with MS Excel 97/2000 if conversion function add-ins are loaded --
number of digits very limited for some conversions)
cnvtr1.123 (Lotus 1-2-3 v.9 file -- will not work with earlier Lotus versions)
cnvtr1.xls (MS Excel 97/2000 file)
If Analysis Toolpak add-ins are loaded into Excel 2000, the above
file will load directly into the IE 5.0 window. Entering a valid decimal,
binary, octal, or hexadecimal number in the appropriate row of the B column
provides automatic conversions in the C, D, and E columns.