Hex to Decimal
Part of the Fundamentals section of Coddy's Assembly journey — lesson 11 of 45.
Hexadecimal (base 16) works the same way as binary and decimal — each position has a place value. In hex, each position is a power of 16.
Place values in hex:
| Position | Power of 16 | Decimal value |
|---|---|---|
| Rightmost | 16⁰ | 1 |
| Next | 16¹ | 16 |
| Next | 16² | 256 |
| Next | 16³ | 4096 |
Hex digit values to remember:
| Hex | Decimal |
|---|---|
| 0-9 | 0-9 |
| A | 10 |
| B | 11 |
| C | 12 |
| D | 13 |
| E | 14 |
| F | 15 |
Example 1: Convert <strong>0x2A</strong> to decimal
| Position | Hex digit | Place value | Calculation |
|---|---|---|---|
| Left | 2 | 16 | 2 × 16 = 32 |
| Right | A (10) | 1 | 10 × 1 = 10 |
| Total | 32 + 10 = 42 |
So 0x2A = 42 in decimal.
Example 2: Convert <strong>0xFF</strong> to decimal
| Position | Hex digit | Place value | Calculation |
|---|---|---|---|
| Left | F (15) | 16 | 15 × 16 = 240 |
| Right | F (15) | 1 | 15 × 1 = 15 |
| Total | 240 + 15 = 255 |
So 0xFF = 255 in decimal.
Example 3: Convert <strong>0x3E8</strong> to decimal
| Position | Hex digit | Place value | Calculation |
|---|---|---|---|
| Left | 3 | 256 | 3 × 256 = 768 |
| Middle | E (14) | 16 | 14 × 16 = 224 |
| Right | 8 | 1 | 8 × 1 = 8 |
| Total | 768 + 224 + 8 = 1000 |
So 0x3E8 = 1000 in decimal.
The formula:
For a hex number with digits ... d₂ d₁ d₀:
Value = (... + d₂ × 16² + d₁ × 16¹ + d₀ × 16⁰)
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
1The Machine
What is CPUMemoryRegisters vs MemoryHow instructions workTwo-File PatternThe x86-64 Architecture2Number Systems
Why Binary?Binary NumbersDecimal to BinaryWhy Hexadecimal?Hex to DecimalDecimal to HexASCII & Hex