Skip to the workspace
Pebellslearn by building
Binary, Hex and Endianness  ›  Lesson

Hexadecimal — Four Bits per Digit

Endianess 12 minHexadecimal is base sixteen, and because one hex digit stands for exactly four bits, two hex digits describe exactly one byte.

computer science / Hexadecimal — Four Bits per Digit

Explore each scene at your own pace.

01 · The rule

The rule

Hexadecimal — Four Bits per Digit

Look at a colour code like #FF8800, a memory address like 0x7ffe, or a network card's address like 3c:22:fb:10:9a:01. They are all hexadecimal. Programmers did not pick base sixteen to be difficult. They picked it because it lines up perfectly with bits.

The rule

One hex digit is four bits; two hex digits are one byte.

Hexadecimal (hex) is base 16. It needs sixteen digits, so after 0–9 it borrows letters:

hex:     0  1  2  3  4  5  6  7  8  9  A   B   C   D   E   F
decimal: 0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15
binary:  0000 … 1001 for 0–9, then 1010 1011 1100 1101 1110 1111

Four bits have exactly 16 patterns, so each hex digit stands for one group of four bits (sometimes called a nibble). A byte is two nibbles, so it is always exactly two hex digits, from 00 to FF. A 32-bit number is always 8 hex digits.

Hex is usually marked with a 0x prefix, as in 0x2F, so it is not confused with decimal.

For the decimal value, the places are worth 1, 16, 256, … So 0x2F = 2 × 16 + 15 = 47.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.