In a previous post, we explored the Binary numbering system. While a stream of zeroes and ones is easy for computers to handle, humans prefer more readable representations of numbers. One of the most common alternatives is Hexadecimal (HEX).
What is Hexadecimal?
Hexadecimal is a base-16 system, meaning it uses 16 symbols to represent values. These symbols are the digits from 0 to 9, and then the letters A to F, representing values 10 to 15. This system provides a more compact way to represent numbers compared to Binary, which only uses 0 and 1. But how do we represent values greater than 9 using only one character? The letters A through F come into play.
For example:
- A represents 10,
- B represents 11,
- C represents 12,
- D represents 13,
- E represents 14,
- F represents 15.
So, if we want to represent the number 12 in HEX, we use C instead of the binary representation, which would require four bits (1100). Isn’t Hex just easier to read? I bet you’ll agree.
Working with Larger Values
Just like how smaller numbers in the HEX system are represented by single characters, larger numbers are represented by multiple HEX digits. These multiple digits can be combined to form bigger values, much like how bricks can be arranged to form a structure. Let’s look at an example:
Decimal (DEC) | Binary (BIN) | Hexadecimal (HEX) |
---|---|---|
132 | 10000100 | 84 |
Wait, how did 132 become 84 in HEX? The trick is that we treat the decimal number as a sequence of HEX digits. In this case, 132 is represented as 84 in HEX.
Decimal to Hexadecimal Conversion
The process of converting from Decimal (DEC) to Hexadecimal (HEX) is very similar to converting from DEC to Binary (BIN). The key difference is that, instead of dividing by 2 (as we do for Binary), we divide by 16. Here’s how we convert 132 from Decimal to Hexadecimal:
Division | Quotient | Remainder |
---|---|---|
132 ÷ 16 | 8 | 4 |
8 ÷ 16 | 0 | 8 |
After the division, we write down the remainders from bottom to top, resulting in 84 in HEX. This conversion allows us to represent the number 132 with only two characters (instead of the three characters we would need in Decimal).
While HEX is more compact than Decimal, dividing by 16 may still be a bit tricky for large numbers. For this reason, it’s a good idea to keep a calculator handy (especially one that supports modulo operations).
Hexadecimal to Decimal Conversion
Converting from Hexadecimal to Decimal is a bit more involved, but it follows a simple pattern. Before we start, you need to answer two questions:
- How many digits does my HEX number have?
- What is the position of each HEX digit? (This is explained in the next section.)
Positioning of HEX Digits
In a multi-digit HEX number, the right-most digit has a position index of 0. The second-to-last digit has an index of 1, and so on. This is important because each position in the HEX number corresponds to a power of 16.
Index | Placement | HEX Digit |
---|---|---|
0 | First | 4 |
1 | Second | 8 |
Calculation
Let’s take the HEX number 84 as an example. To convert it to Decimal, we use the following formula:
Decimal = (8 × 16^1) + (4 × 16^0)
Breaking it down:
- ( 8 \times 16^1 = 128 )
- ( 4 \times 16^0 = 4 )
Adding them together gives us 132 in Decimal. So, the HEX value 84 is equivalent to 132 in Decimal.
Summary
Now you’re familiar with three key number representation systems:
- Decimal (DEC)
- Binary (BIN)
- Hexadecimal (HEX)
With this foundational knowledge, you are ready to tackle problems involving number conversions and more.