Hexadecimal

Lingua Franca

We have discussed two commonly used bases for encoding numeric information—base 2 (binary) and base 10 (decimal). Each of these serves as a “native encoding”—binary for digital devices and decimal for humans.

  • Binary is convenient notation for computers because digital circuits are essentially a collection of on/off switches. Remember that the underlying concept of binary notation is the representation of information as a series of dichotomies. The dichotomies may be represented in a number of ways—including on/off or 0/1.
  • Decimal is convenient notation for modern humans. Most languages use decimal as the basis for numeral representation. Many have proposed that base 10 is used because people learn to count using their 10 fingers. There may be truth to this. The Yuki tribe in California counted with the spaces between their fingers, and because of this, they used base 8 to represent numbers!

Computers use binary by necessity because it best complements the underlying hardware. Why don’t humans use binary? Perhaps it is because the length of binary numerals can grow quite large quickly. The three digits of 999 in decimal are equivalent to eight digits in binary—11100111. Beyond this, the use of only two symbols may make numerals hard to read. Which pair is more distinct—999 and 723—or 11100111 and 11010011?

Because of this, computer scientists use a third base to serve as a lingua franca—a language that is adopted as a common language between speakers whose native languages are different.

Binary Abbreviated

Base 16—hexadecimal—is commonly used as this lingua franca. Why base 16?

Consider the following table:

Binary Decimal Hexadecimal
0000 0 0
0001 1 1
0010 2 2
0011 3 3
0100 4 4
0101 5 5
0110 6 6
0111 7 7
1000 8 8
1001 9 9
1010 10 A
1011 11 B
1100 12 C
1101 13 D
1110 14 E
1111 15 F

Note that the numerals are padded to the left with zeroes so that the binary column has the same number of digits. This does not affect the values. Why?

Using the 16 symbols of hexadecimal, you can represent all the possible permutations of four bits! Note that the symbols A–F are used to extend the numerals representing each digit beyond those of decimal—A is equivalent to 10, and F is equivalent to 15. Hexadecimal serves as an abbreviated form of binary!

Hexadecimal is common when representing RGB colors. RGB uses 24 bits—eight for the red channel, eight for the green channel, and eight for the blue channel. So, the following color:

is represented as 001101011001110010001111 in binary. This is difficult to read. However, splitting the numerals into groups of four, 0011 0101 1001 1100 1000 1111, we can easily convert this long string of 0s and 1s into 359C8F in hexadecimal:

0011 0101 1001 1100 1000 1111
0011 0101 1001 1100 1000 F
0011 0101 1001 1100 8 F
0011 0101 1001 C 8 F
0011 0101 9 C 8 F
0011 5 9 C 8 F
3 5 9 C 8 F

The algorithm to convert binary to hexadecimal is as follows:

  1. Starting at the right most digit of the binary number, isolate four digits.
  2. Replace the four digits with their equivalent hexadecimal numeral.
  3. Repeat steps 1 and 2, moving leftward.

If the final sequence of bits numbers less than four, insert 0s to the left until the sequence is four digits long.

Exercises

Convert the follow from binary to hexadecimal:

1) 110010102 =

Answer:

2) 10101010012 =

Answer:

3) 101011100011110101110102 =

Answer:

4) 1111110110110100001010112 =

Answer:

5) 1010101111001101111011112 =

Answer:


Try using the table in reverse! Convert from hexadecimal to binary:

6) 1416 =

Answer:

7) C416 =

Answer:

8) 38716 =

Answer:

9) FFFF16 =

Answer:

10) B7F5CA16 =

Answer: