Skip to content
BetterDL

Hexadecimal

Also called: hex, base 16, base-16

The base-16 number system, with digits 0–9 and A–F (10–15). One hex digit stands for exactly 4 bits, so hex is a compact way to write binary.

Hexadecimal (hex) is base 16. It needs sixteen digit symbols, so after 0–9 it uses letters: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. Place weights are powers of 16: 1, 16, 256, 4096, …

Hex exists because people are bad at reading long binary. Since 16 = 2⁴, one hex digit is exactly one 4-bit nibble, so converting between hex and binary is a lookup. The 16-bit pattern 1101 0110 0010 1111 is just D62F₁₆.

Where you'll see it:

  • memory addresses and register contents in a debugger
  • web colors such as #FF8800 (three bytes: red, green, blue)
  • machine code, error codes and network hardware addresses

In code, hex is usually marked with a 0x prefix: 0x2F = 2F₁₆ = 47. See base notation.

Conversions:

2
16¹
F
16⁰

Worked examples

Example

1A3₁₆ to decimal

Multiply each digit by its power of 16.

  1. 1.

    1 in the 256s place: 1 × 256 = 256.

  2. 2.

    A (10) in the 16s place: 10 × 16 = 160.

  3. 3.

    3 in the 1s place: 3 × 1 = 3.

  4. 4.

    Total: 256 + 160 + 3 = 419.

Example

C5₁₆ to binary

Replace each digit with its nibble.

  1. 1.

    C = 12 = 1100.

  2. 2.

    5 = 0101.

  3. 3.

    Result: 11000101₂. Check: 128 + 64 + 4 + 1 = 197 = 12 × 16 + 5.

Common mistakes

  • Reading hex digits as decimal: 36₁₆ is 3 × 16 + 6 = 54, not thirty-six.

  • Writing a remainder of 12 as the two digits "12" instead of the single digit C.

  • Grouping binary into fours from the left instead of from the right.

Practice Hexadecimal

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Hexadecimal is taught in Number Systems.