Celtic Kane

What are octal and hexidecimal numbers?

Octal and hexidecimal numbers are number systems that use a different number of bases. Our number system uses the base-10 system, where we have a total of 10 possible digits (0-9). If you read the previous page, binary numbers are base-2 numbers, where they have 2 possible numbers (0 and 1). Octal is simply a number system that is base-8, and hexidecimal is a number system that is base-16.

How can you have 16 possible digits?

Because we only have the numbers 0 through 9, we have to use more digits that act as numbers in base 16. We can’t use 10 or 11 because those are two-digit numbers. Instead, hexidecimal uses the letters A through F…A represents the base-10 value of 10, and F represents 15.

There is a very small difference between base-2 and all other bases. In base-2 (binary), after we did 2^(digit number) we were done (assuming the value of that digit was a 1 and not a 0). Now, since we can have more than just a 1 or a 0, we have to multiply the power raised by the digit. Let’s check out some examples to see what I’m talking about…

Examples of Converting Binary to Decimal

Octal -> 144

Decimal: Okay, let’s look at the digits. You always read numbers numbers from right to left. The right-most digit is a 4, and it’s corresponding value is 8^0, which is 1. But here’s the catch: unlike in binary, we have to multiply the 8^0 by the digit’s value of 4. So instead of the left-most digit representing 1, it represents 4. This makes sense, because if we didn’t multiply a left-most value of 1 and 4 would return the same value, and they obviously are not the same. The next digit is a 4, so we take 8^1 (which is eight) times 4, which is 32. The next digit (and the left-most) is a 1, and it’s corresponding value is 8^2, which is 64 but we have to multiply by 1, and we get 64. So we add up our values…4 + 32 + 64 = 100. Therefore, the octal number 144 is equivalent to the decimal number of 100.

Octal -> 77

Decimal: 8^0*7 + 8^1*7 = 63

What about hexidecimal?

Hexidecimal works the exact same way. Let’s do a quick example and I’m sure you’ll catch on immediately because it’s essentially the same pattern.

Hexidecimal -> AD5B

Decimal: Okay, just like always we’ll start on the right-hand side. The first digit is B, which is represented by the value of 11 (A is 10, B is 11, C is 12, etc.). So we take 16^0 * 11, which equals 11. The next digit is 16^1 * 5, which is 80. The third digit is D, which is represented by the value of 13…so 16^2 * 13, which is 3328. Finally, the last digit is an A, which is represented by the value of 10. So we get 16^3 * 10, which is 40960. Now we add them all up: 11 + 80 + 3328 + 40960 = 44379.

Hexidecimal -> AB

Decimal: 16^0*11 + 16^1*10 = 171

A huge timesaver

Sometimes you’ll be asked to convert from binary to hexidecimal/octal or vice versa. Normally you would have to conver the number to base-10, then to the respective base. But no! There’s a much easier and faster way. If you’re given a binary number…say 11011111 and you’re asked to conver to hexidecimal, split the number into groups of four (so we’ll get 1101 and 1111) then convert each group into its hexidecimal value (1101->D, 1111->F). Finally, just put the hexidecimal values together and you’ll get the answer: DF. The pattern works similarly to octal, except you do groups of three. Let’s check out a few examples to make this concept concrete…

Binary -> 111110010

Octal: Split the number into groups of three: (111)(110)(010). Next, convert each group into octal: (7)(6)(2). Finally, put all the octal numbers together (DON’T ADD! Just push them all together) and you get an octal value of 762.

Binary -> 11 101 110

Octal: Easy, right? Well let’s split it up into groups. Big note: always start grouping from the right, NOT THE LEFT! If we group from the right, we’ll get (11)(101)(110). See the problem? The left-most group only has two digits, not three like we wanted. What should we do? Well…remember in binary numbers how you can add 0’s to the right and it won’t change the number (ie-> 00010 is the same as 10). All we have to do is add a zero: (011)(101)(110), convert to octal: (3)(5)(6), and push all the numbers together and voila: 356.

Conclusion

There isn’t really a whole lot of difference between converting binaries and converting hexidecimal or octal. Now that you know the pattern, you should be able to convert using any base you want (try base-4, base-20, etc.). If you’re feeling especially lazy, you can always use the windows calculator in advanced mode to convert for you. Go to start>run>type in “calc” (no quotes), and hit OK. In the menu at the top, go to VIEW, then set it to SCIENTIFIC. In the top left, you should see HEX, DEC, OCT, BIN. Guess what those mean? If you type in a number when DEC is selected, all you have to do is click on any of the other number systems and it will convert the number on the screen for you.


Previous: Binary Numbers
Next: Conditional Logic