Friendly Expert Computer Help - In Plain English

 PC911 > How-To > Miscellaneous > Understanding the Hexadecimal Number System

- ChrisP -

Hex - what is it, and why do I need it?

By now, most of us are aware that computers are binary devices - that is, everything in a computer comes down to just two states. Any written character, any color, or any audio tone reproduced by a computer in any form exists as a binary value. If this is news to you, take a few minutes to browse through our PC911 How-To on the binary number system before continuing with this article, as a basic understanding of base-2 is important if this article is going to make sense to you.

In our everyday world, we commonly use a numbering system universally known as the decimal system or base-10. In this system, we use ten unique glyphs (numerals) to represent known values. These values start at zero (represented by 0) and increase to a maximum of nine (represented by 9). The greatest value that can thus be expressed by a single glyph is the value "nine". In order to express a value greater than nine, we must add a second glyph to our depiction of the value. In this case, the placement of this new glyph is critical to our understanding of the value represented by the glyph.

Consider the decimal value 75. When we see this value written as such, we automatically understand that the glyph 7 in the left-most column represents seven sets of ten, and that the glyph 5 in the right-most column represents five sets of one. If the written value were to be a three-digit value, we would then understand the now left-most column represents a certain quantity of a differently valued set purely by virtue of its position in the written representation of the total value.

We know all of this already, right? After all, we've been using this system all of our lives. The decimal number system has the primary advantage of being easily understood while not producing excessively clumsy written representations of large values. We have even invented some shorthand to further simplify these numbers. The terms million, billion, and trillion are proper terms used in the decimal system, but don't we commonly refer to the value 32,780,000,000 as "thirty two point seven-eight billion"? That is more readily understood than the long term "thirty two billion seven hundred eighty million".

OK - back on topic - computers use the binary or base-2 system. Base-2 can produce uncomfortably long written representations of even fairly low values. Consider the decimal value 9. This value, which is represented by a single digit in base-10, becomes 1001 in base-2 simplest form - a four-digit representation. Base-2 was selected due to its direct correspondence to useful electrical states (on or off) and basic decisions (yes or no). This works very well for extremely low values, but becomes troublesome as the expressed value grows.

Let's look at the binary representation of the decimal value 365. In base-2, this value would be written as 1 0110 1101. Do the arithmetic ... 2^8 + 2^6 + 2^5 + 2^3 + 2^2 + 2^0 = 256 + 64 + 32 + 8 + 4 + 1 = 365. Again, if you don't follow how this works, read the How-To that I referenced earlier. Let's face it, as convenient as base-2 is for some things, it certainly is not so for expressing large values. So if base-2 isn't good here, what would be? In order to maintain some semblance of continuity, we must select a number system that allows simplified expression of large values but that also has some commonality with the binary system. This commonality is found in a number system whose base is also a power of two. The decimal system (base-10) is out then, right? The most obvious choices would be base-4, base-8, and base-16. Base-4 would not offer much advantage, as it would still result in fairly lengthy expressions of large values. That leaves us to choose between base-8 and base-16.

In reality, both base-8 (octal) and base-16 (hexadecimal) are used in the computer field, although today, hexadecimal (abbreviated hex or simply h) is in much more common usage. This number system is uses sixteen unique glyphs as its digits, with the number of columns increasing as the expressed value increases. Even the smallest values are customarily written in two-digit format using a leading zero, and with a hex indicator following the expression: 04h or 04hex. You will commonly see hex expressions used when discussing memory addresses and Input/Output ranges as hardware resources.