Skip to content
Tactiverge

Digital logic

Hexadecimal

Also called: hex · base 16 · 0x · nibble

Definition

Hexadecimal is base 16, using digits 0–9 and A–F. Each hex digit stands for exactly four bits, so two hex digits describe one byte.

Picture it

Hex is shorthand for binary that humans can read. 0xC8 is 1100 1000: translate each digit to four bits and back. Memory addresses, colour codes and register values are written in hex because the bit pattern stays visible.

The maths

value = Σ h_i × 16^i
1 hex digit = 4 bits
SI units used in this entry
QuantityUnitSymbol
informationbitbit
ratiodimensionless1

Worked example

Convert 0x3F to decimal and to binary. What is 0xFF + 1 in an 8-bit register?

  1. 3 × 16 + 15 = 63
  2. 3 → 0011, F → 1111 → 0011 1111
  3. 0xFF = 255; 255 + 1 = 256 does not fit in 8 bits and wraps to 0

Answer0x3F = 63 = 0011 1111; 0xFF + 1 wraps to 0 in 8 bits.

✓ The 2 numbers in this answer are recomputed from scratch by an automated test.

flip the bits

Binary, decimal and hex

Unsigned: 182 · Two's complement: -74 · Hex: 0xB6

Unsigned and two's-complement readings of the same bit pattern. Python ints are unbounded; microcontroller registers are not.

Common misconceptions

  • Misconception: 0x10 is sixteen, not ten.
  • Misconception: Hex is not a different kind of number; it is just a different way of writing the same value.