Understanding Hexadecimal Number System
What the Heck Is Hexadecimal?
Hexadecimal is a base-16 number system. Instead of counting 0-9 like you do with decimal, you count 0-15 before rolling over to the next digit.
The digits go: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
That's 16 symbols total. Hence "hex" — which means six, and "decimal" — which means ten. Six plus ten equals sixteen. The naming is lazy, but the system is not.
You'll see hex everywhere in programming, web development, and IT. If you've ever seen a color code like #FF5733 or looked at memory addresses in a debugger, you've already encountered it.
Why Programmers Actually Use It
Computers think in binary. Zeros and ones. But binary is ugly to read. A single byte looks like this in binary: 11010111. Nobody wants to debug that.
One hex digit represents exactly four binary digits. So one byte (8 bits) becomes just two hex digits. Much cleaner.
Example:
- Binary:
11010111 - Hex:
D7
That's the real reason hex exists. It's a human-readable shorthand for binary. Nothing more, nothing less.
How Hexadecimal Counting Works
You already know how decimal works. After 9 comes 10. The digit resets and you carry a 1 to the next place.
Hex follows the same logic, just with more digits:
- After 9 comes A (which equals 10 in decimal)
- After B comes C (11)
- After C comes D (12)
- After D comes E (13)
- After E comes F (14)
- After F comes 10 (which equals 16 in decimal)
Think of it like an odometer rolling over, but with more digits available before each rollover.
Place Values in Hex
Each position in a hex number represents a power of 16:
- Rightmost digit: 16⁰ = 1
- Next digit: 16¹ = 16
- Next digit: 16² = 256
- Next digit: 16³ = 4096
So the hex number 1F means: (1 × 16) + (15 × 1) = 16 + 15 = 31 in decimal.
Hex to Decimal Conversion
Here's the formula: multiply each digit by its place value, then add them up.
Let's convert 2AF to decimal:
- A = 10, F = 15
- (2 × 16²) + (10 × 16¹) + (15 × 16⁰)
- (2 × 256) + (10 × 16) + (15 × 1)
- 512 + 160 + 15 = 687
That's it. No magic. Just multiplication and addition.
Decimal to Hex Conversion
This requires dividing by 16 and keeping track of remainders.
Let's convert 687 to hex:
- 687 ÷ 16 = 42 remainder 15 (which is F)
- 42 ÷ 16 = 2 remainder 10 (which is A)
- 2 ÷ 16 = 0 remainder 2
Read the remainders from bottom to top: 2AF
Matches our previous calculation. The math checks out.
Hex to Binary Conversion (The Useful Part)
This is where hex shines. Each hex digit maps directly to exactly 4 binary bits.
| Hex | Binary | Decimal |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| A | 1010 | 10 |
| B | 1011 | 11 |
| C | 1100 | 12 |
| D | 1101 | 13 |
| E | 1110 | 14 |
| F | 1111 | 15 |
To convert hex to binary: replace each hex digit with its 4-bit equivalent.
Example: 3F becomes 0011 1111
To convert binary to hex: group bits in sets of four, starting from the right, then replace each group with its hex digit.
Where You'll Actually See Hexadecimal
CSS Color Codes
Every color you pick in design software maps to a hex code. #000000 is black. #FFFFFF is white. #FF0000 is pure red.
The format is RRGGBB — two digits each for red, green, and blue values (0-255). FF in hex = 255 in decimal = full intensity for that channel.
Memory Addresses
When debugging code, memory addresses look like 0x7FFE1234. The 0x prefix indicates hex notation in most programming languages.
32-bit systems use 8 hex digits for addresses. 64-bit systems use 16 hex digits. This isn't arbitrary — it matches the address bus width of the hardware.
Network MAC Addresses
Network hardware identifiers look like 00:1A:2B:3C:4D:5E. Each pair is a hex byte representing 0-255. No coincidence.
Assembly and Low-Level Programming
Machine code and assembly instructions are often documented in hex. Opcodes, offsets, register values — hex makes the dump readable when you're staring at a crash log at 2 AM.
How to Get Started: Reading and Writing Hex
You don't need a calculator for basic hex work. Memorize the table above. That's 16 entries. You already know 0-9. The hard part is A-F.
Once you know the mapping, you can:
- Read hex color codes — Figure out if a color is reddish, bluish, or dark just by looking at the digits
- Debug memory dumps — Spot patterns in hex data instead of scrolling through binary garbage
- Convert between systems — Hex ↔ binary is instant with the table. Hex ↔ decimal requires basic math
Try this: What is ACE in decimal?
- A = 10, C = 12, E = 14
- (10 × 16²) + (12 × 16¹) + (14 × 16⁰)
- 2560 + 192 + 14 = 2766
Do a few of these by hand. You'll get comfortable with it faster than you expect.
Common Mistakes to Avoid
- Forgetting that A=10, not 14 — The alphabet ordering trips people up. Count: A(10), B(11), C(12), D(13), E(14), F(15).
- Confusing hex notation — Some languages use
0xprefix (C, Python, JavaScript). Others use$(Pascal, some assembly). Know your context. - Assuming uppercase vs lowercase matters — It doesn't.
0x1fand0x1Fare identical. - Forgetting leading zeros —
0Fis not the same asF. The leading zero is just notation, but it matters when you're counting bytes.
The Bottom Line
Hexadecimal is not complicated. It's a base-16 number system that maps cleanly to binary. That's the entire story.
You need it because reading 0xFFFF is infinitely better than reading 1111111111111111. Memory addresses, color codes, network IDs — they're all expressed in hex because humans can parse it without going blind.
Memorize the 16-entry table. Practice a few conversions by hand. That's all it takes to stop being confused by those weird letter-digit combinations you see in code.