6 Octal and Hexadecimal

We have already explored octal (base-8) numbers. Hexadecimal means base-16 (hexa is 6, plus deci is 10, hence 16).

Hold on a second here, how can we represent a number in base-16? After all, we only have 10 digits.

Well, we will borrow characters from the alphabet. Specifically, we'll borrow the letters (case-insensitive) `a' to `f'. `a' means decimal 10, `b' means decimal 11, and etc.

Let's backtrack a little bit, why are we particularly interested in base-8 and base-16, when our primary interest is base-2? Both 8 and 16 are powers of 2. This permits very efficient conversion between binary numbers and octal/hexadecimal numbers.

But why do we want to use base-16 numbers?

This example should suffice. The binary number 00110101011011001111(2) is represented as hexadecimal number 3a6cf(16). I don't know about you, but the hexadecimal form is much easier to spell out, write down and remember.

How do we convert a binary number to hexadecimal? Here's how.

The lookup table is as follows:

binary hexadecimal
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 a
1011 b
1100 c
1101 d
1110 e
1111 f

The conversion from hexadecimal to binary is just to look up the table in reverse (from the right column to the left column).

Octal numbers are rarely used nowadays, but its conversion to/from binary is about the same, only the table is smaller, and we use chunks of 3 binary digits.

Copyright © 2006-08-21 by Tak Auyeung