# Shortcut Conversions

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Because both the octal and hexadecimal bases contain $2^{3}$ and $2^{4}$ possible digits, respectively, and the binary base contains $2^{1}$ 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:

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.

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 $11000111\;\;00100101_{2}$ , regroup the binary digits in sets of four:
$11000111\;\;00100101_{2}$ $\color {Orange}1100\color {Blue}0111\;\;\color {Orange}0010\color {Blue}0101\color {Black}_{2}$ $\color {Orange}1100\;\;\color {Blue}0111\;\;\color {Orange}0010\;\;\color {Blue}0101\color {Black}_{2}$ .

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

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

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 $11000111\;\;00100101_{2}$ , regroup the binary digits in sets of three:
$11000111\;\;00100101_{2}$ $\color {Orange}1\color {Blue}100\color {Orange}011\color {Blue}1\;\;00\color {Orange}100\color {Blue}101\color {Black}_{2}$ $00\color {Orange}1\;\;\color {Blue}100\;\;\color {Orange}011\;\;\color {Blue}100\;\;\color {Orange}100\;\;\color {Blue}101\color {Black}_{2}$ .

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

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)

This requires slightly more work. Convert the number in the source base to binary, and then convert from binary to the target base.

Number Systems : 7 of 7