The hexadecimal number system is base . It uses sixteen distinct digit symbols: and then for values through .

Hex is everywhere in computing because it lines up cleanly with binary: every hex digit corresponds to exactly bits (). Reading or writing memory addresses, machine code, byte values — anything binary that’s more than a few bits — is easier in hex than in binary.

Hex digit table

DecimalBinaryHex
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
101010A
111011B
121100C
131101D
141110E
151111F

Notation

Hex literals are typically prefixed to mark the base:

  • 0xFF — common in C, JavaScript, Python.
  • \$FF or #FF — assembly.
  • — math notation.

The prefix is purely a label; the value is the same regardless of how you write it. .

Conversion to decimal

Standard positional expansion: each hex digit times its place value.

Conversion to/from binary

The killer feature of hex: every digit is exactly 4 bits. To convert hex → binary, replace each hex digit with its 4-bit pattern. Concatenate the results — no decimal in the middle.

To go binary → hex, group the bits into chunks of 4 starting from the right (the radix point), then map each chunk to its hex digit.

If the leftmost group is short, pad with leading zeros: .

Why it’s useful

Three places hex shows up constantly:

  1. Memory addresses. A 32-bit address has 8 hex digits — much easier to read and write than 32 binary digits.

  2. Byte values. Each byte fits in 2 hex digits ( to ). Color codes (#FF8800), MAC addresses (AA:BB:CC:DD:EE:FF), checksums — all conventional in hex.

  3. Bit patterns in code. When you need a specific 32-bit constant in software, writing 0xFFFF0000 is far less error-prone than writing .

For the general theory of converting between any two bases, see Base Conversion.