Because both the octal and hexadecimal bases contain and possible digits, respectively, and the binary base contains possible digits, we're able to utilize a shortcut when converting between these systems. Note that each octal digit is comprised of three binary digits and each hexadecimal digit is comprised of four binary digits. We can therefore establish (and memorize) the following table:
Decimal | Binary | Octal | Hexadecimal |
---|---|---|---|
00 | 0000 | 00 | 0 |
01 | 0001 | 01 | 1 |
02 | 0010 | 02 | 2 |
03 | 0011 | 03 | 3 |
04 | 0100 | 04 | 4 |
05 | 0101 | 05 | 5 |
06 | 0110 | 06 | 6 |
07 | 0111 | 07 | 7 |
08 | 1000 | 10 | 8 |
09 | 1001 | 11 | 9 |
10 | 1010 | 12 | A |
11 | 1011 | 13 | B |
12 | 1100 | 14 | C |
13 | 1101 | 15 | D |
14 | 1110 | 16 | E |
15 | 1111 | 17 | F |
The shortcut is very straight-forward yet a significant time saver and based on the above information. When converting between binary, octal, and hexadecimal, there's no need to use an intermediate, decimal step.
Binary to Hexadecimal[edit]
Group the binary number in sets of four digits, from right to left. Each binary set represents a single hexadecimal digit. (It's sometimes helpful to pad the final set with zeroes.) For example, given the number , regroup the binary digits in sets of four:
.
Then, use the memorized table to translate each set of four binary digits to a single hexadecimal digit:
1100 | 0111 | 0010 | 0101 |
C | 7 | 2 | 5 |
Hexadecimal to Binary[edit]
Simply follow the above procedure in reverse. Use the memorized table to convert each hexadecimal digit to a set of four binary digits.
Binary to Octal[edit]
Group the binary number in sets of three digits, from right to left. Each binary set represents a single octal digit. (It's sometimes helpful to pad the final set with zeroes.) For example, given the number , regroup the binary digits in sets of three:
.
Then, use the memorized table to translate each set of three binary digits to a single octal digit:
001 | 100 | 011 | 100 | 100 | 101 |
1 | 4 | 3 | 4 | 4 | 5 |
Octal to Binary[edit]
Simply follow the above procedure in reverse. Use the memorized table to convert each octal digit to a set of three binary digits.
Octal to Hexadecimal (and vice versa)[edit]
This requires slightly more work. Convert the number in the source base to binary, and then convert from binary to the target base.