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—
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.
Base 16—hexadecimal—is commonly used as this lingua franca. Why base 16?
Consider the following table:
†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:
- Starting at the right most digit of the binary number, isolate four digits.
- Replace the four digits with their equivalent hexadecimal numeral.
- 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.
Convert the follow from binary to hexadecimal:
Try using the table in reverse! Convert from hexadecimal to binary: