Click here to purchase the entire book in PDF format.



next up previous contents index
Next: Other Bases Up: Binary, Decimal and Hexadecimal Previous: Binary (Base 2)   Contents   Index


Hexadecimal (Base 16)

The advantage of binary is that we only need two digits (0 and 1) or two ``states'' (on and off, short and long etc...) to represent the binary word. The disadvantage of binary is that it takes so many bits to represent a big number. For example, the fifteen-bit word 111111111111111 is the same as the decimal number 32768. I only need five digits to express in decimal the same number that takes me fifteen digits in binary. So, let's invent a system that has too much of a good thing: we'll go the other way and pretend we all have sixteen fingers.

Let's count again: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ... now what? We can't go to ``10'' yet because we have six more fingers left... so we need some new symbols to take care of the gap. We'll use letters! A, B, C, D, E, F, 10, 11, 12, huh?

Remember, we're assuming that we have sixteen digits to use, therefore there have to be sixteen individual symbols to represent the numbers zero through to fifteen. Therefore, we can make the Table 1.4:


Table 1.4: The numbers zero through to sixteen and the corresponding representations in decimal, hexadecimal, and binary.
Number Decimal Hexadecimal Binary
zero 0 0 0000
one 1 1 0001
two 2 2 0010
three 3 3 0011
four 4 4 0100
five 5 5 0101
six 6 6 0110
seven 7 7 0111
eight 8 8 1000
nine 9 9 1001
ten 10 A 1010
eleven 11 B 1011
twelve 12 C 1100
thirteen 13 D 1101
fourteen 14 E 1110
fifteen 15 F 1111
sixteen 16 10 10000


So, now we wind up with these strange numbers that include the letters A through F. So we'll see something like 3D4A. What number is this exactly?


Table 1.5: A breakdown of an abritrary hexadecimal number 3D4A, converting it to a decimal number. Note that hexadecimal and decimal are used simultaneously in this table: to distinguish the two, all hexadecimal numbers are in italics.
3   D   4   A
4096's   256's   16's   1's
3$ * 16^{3}$ + D$ * 16^{2}$ + 4$ * 16^{1}$ + A$ * 16^{0}$
3$ * 4096$ + D$ * 256$ + 4$ * 16$ + A$ * 1$
$3 * 4096$ + $13 * 256$ + $4 * 16$ + $10 * 1$
12288 + 3328 + 64 + 10
    = 15690        


If this seems a little confusing at this point, don't panic. It does for everyone. I think that the confusion with hexadecimal arises from the fact that it's so close to decimal - you can have the number 246 in decimal and the number 246 in hexadecimal - but these are not the same number, so you have to translate. (for example, the German word for ``poison'' is ``Gift'' - so if you're reading in German, this is not a word that you should think in English. An English ``gift'' and a German ``Gift'' are different things... hopefully...)

Of course, this raises the question ``Why would we use such a confusing system in the first place!?'' The answer actually lies back in the binary system. All of our computers and DSP and digital audio everything use the binary system to fire numbers around. This is inescapable. The problem is that those binary words are just so long to write down that, if you had to write them in a book, you'd waste a lot of paper. You could translate the numbers into decimal, but there's no correlation between binary and decimal - it's difficult to translate. However, check back to Table 3. Notice that going from the number fifteen to the number sixteen results in the hexadecimal number going from a 1-digit number to a 2-digit number. Also notice that, at the same time, the binary word goes from 4 bits to 5. This is where the magic lies. A single hexadecimal digit (0 - F) corresponds directly to a four-bit binary word (0000 - 1111). Not only this, but if you have a longer binary word, you can slice it up into four-bit sections and represent each section with its corresponding hexadecimal digit. For example, take the number 38069:

1001010010110101

Slice this number into 4-bit sections (start slicing from the right)

1001 0100 1011 0101

Now, look up the corresponding hexadecimal equivalents for each 4-bit section using Table 1.4:

9 4 B 5

94B5

So, as can be seen from the example above, there is a direct relationship between each 4-bit ``slice'' of the binary word and a corresponding hexadecimal number. If we were to try to convert the binary word into decimal, it would be much more of a headache. Since this translation is so simple, and because we use one quarter the number of digits, you'll often see hexadecimal used to denote numbers that are actually sent through the computer as a binary word.


next up previous contents index
Next: Other Bases Up: Binary, Decimal and Hexadecimal Previous: Binary (Base 2)   Contents   Index
Geoff Martin 2006-10-15

Click here to purchase the entire book in PDF format.