The Hexadecimal Number System: The Language of Programmers
Few programmers can read the byte 01101110 at a glance, but almost anyone can read 0x6E. The hexadecimal system (hex) is not another kind of "math" — it is a compact shorthand for binary, existing only so people don't get lost in long strings of zeros and ones. Let's see why one hex digit is exactly four bits and how to convert numbers by eye.
Why another number system
Binary is honest to the hardware but hard on the eyes: a byte is eight characters, two bytes are sixteen, all of them 0 and 1. Decimal is compact but blind to the hardware: to see which bits sit inside the number 254, you would have to divide with remainders.
Hexadecimal is the compromise: 16 = 2⁴, so each hex digit maps onto four bits at once, with no arithmetic. Converting hex ↔ binary is not math but recoding: take a nibble, look it up in a 16-row table.
One digit — four bits
The hex digits are 0–9 plus the letters A–F (A = 10, B = 11, … F = 15). Sixteen values — exactly as many as four bits can hold. The habit forms quickly:
| Binary nibble | Hex | Decimal |
|---|---|---|
| 0000 | 0 | 0 |
| 0011 | 3 | 3 |
| 0110 | 6 | 6 |
| 1000 | 8 | 8 |
| 1010 | A | 10 |
| 1111 | F | 15 |
Converting by hand
Hex → binary. Split the number into digits and replace each with its nibble: 0x6E → 6 = 0110, E = 1110 → 01101110. No addition involved.
Binary → hex. Split the bits into groups of four from the right (for a byte — just in half) and replace each group with a digit: 10110011 → 1011 = B, 0011 = 3 → 0xB3.
Hex → decimal. Here arithmetic returns: multiply the high digit by 16. 0x6E = 6·16 + 14 = 96 + 14 = 110. For a byte there is a shortcut: the high digit is "that many times sixteen", the low digit is as-is.
0xFF, masks and colors
A byte of eight ones, 11111111, is 0xFF — 255. In the course this byte appears constantly: the RAM_SEL8 mask from the bus article is 0xFF when the RAM may speak and 0x00 when it stays silent. The display and gamepad ports are addresses 0xFA–0xFF from the memory-mapped I/O article.
The same system rules beyond circuitry: web colors are three bytes in hex (#FF7A00 is orange: red FF, green 7A, blue 00). Once you can read hex, you can read half of all technical documentation.
Practice: the number base converter translates binary, decimal and hexadecimal both ways, including two's complement for negative numbers.
Test yourself
Why is one hex digit exactly four bits?
Because 16 = 2⁴: the sixteen values of a digit match the number of combinations of four bits.
Convert 0xA3 to binary.
A = 1010, 3 = 0011, so 0xA3 = 10100011.
What is 0xFF in decimal, and why does it matter for a byte?
15·16 + 15 = 255. It is the byte maximum: all eight bits are 1, every wire is "on".