
Octal & Hexadecimal Numbers
Shorthand for binary: octal packs 3 bits per digit, hex packs 4 bits per digit.
Description
Bases 8 and 16 used as compact stand-ins for long binary strings. Binary is error-prone to read; one hex digit replaces four bits at a glance. Group binary bits (3 for octal, 4 for hex) from the radix point and map each group to a digit.
- Hex: split binary into 4-bit groups from the right; map each to 0–9, A–F.
- Octal: split into 3-bit groups; map each to 0–7.
- Pad the leftmost group with leading zeros if needed.
- Modern word sizes (8/16/32/64) are multiples of 4 → clean hex alignment.
- Two hex digits = one byte, the universal unit of memory.
- What: Bases 8 and 16 used as compact stand-ins for long binary strings.
- Why: Binary is error-prone to read; one hex digit replaces four bits at a glance.
- How: Group binary bits (3 for octal, 4 for hex) from the radix point and map each group to a digit.
- Where: Memory addresses, color codes (#RRGGBB), machine code, register dumps.
- When: Anywhere binary values must be displayed or typed by people.
At a glance
What
Bases 8 and 16 used as compact stand-ins for long binary strings.
Why
Binary is error-prone to read; one hex digit replaces four bits at a glance.
How
Group binary bits (3 for octal, 4 for hex) from the radix point and map each group to a digit.
Where
Memory addresses, color codes (#RRGGBB), machine code, register dumps.
When
Anywhere binary values must be displayed or typed by people.
Think of it like…
Like packing loose bits into boxes: hex uses boxes of 4 bits, octal boxes of 3. One box label (a hex/octal digit) stands in for the whole box — shorter to write, same contents.
Grouping rule
- Hex: split binary into 4-bit groups from the right; map each to 0–9, A–F.
- Octal: split into 3-bit groups; map each to 0–7.
- Pad the leftmost group with leading zeros if needed.
Why hex dominates
- Modern word sizes (8/16/32/64) are multiples of 4 → clean hex alignment.
- Two hex digits = one byte, the universal unit of memory.
Hex digit map
| Binary | Hex | Binary | Hex |
|---|---|---|---|
| 0000 | 0 | 1000 | 8 |
| 0001 | 1 | 1001 | 9 |
| 0010 | 2 | 1010 | A |
| 0011 | 3 | 1011 | B |
| 0100 | 4 | 1100 | C |
| 0101 | 5 | 1101 | D |
| 0110 | 6 | 1110 | E |
| 0111 | 7 | 1111 | F |
Convert decimal to octal / hex
▶ live simulator| step | value ÷ 2 | quotient | remainder |
|---|---|---|---|
| 1 | 156 ÷ 2 | 78 | 0 |
| 2 | 78 ÷ 2 | 39 | 0 |
| 3 | 39 ÷ 2 | 19 | 1 |
| 4 | 19 ÷ 2 | 9 | 1 |
| 5 | 9 ÷ 2 | 4 | 1 |
| 6 | 4 ÷ 2 | 2 | 0 |
| 7 | 2 ÷ 2 | 1 | 0 |
| 8 | 1 ÷ 2 | 0 | 1 |
Read remainders bottom-to-top → 10011100
The 5 Whys
- 1
Why octal/hex? To write binary compactly without losing information.
- 2
Why compactness? Long bit strings are hard to read and easy to mistype.
- 3
Why 3 and 4 bits specifically? 8 = 2³ and 16 = 2⁴, so grouping is exact.
- 4
Why does exact grouping matter? It makes conversion lossless and instant.
- 5
Root cause: choosing a base that is a power of two makes binary↔base mapping a pure regrouping.
Cheat sheet
Working principle
- Group binary bits (3 for octal, 4 for hex) from the radix point and map each group to a digit.
- Bases 8 and 16 used as compact stand-ins for long binary strings.
Formulas & Boolean expressions
- Two hex digits = one byte, the universal unit of memory.
Key facts
- Hex: split binary into 4-bit groups from the right; map each to 0–9, A–F.
- Modern word sizes (8/16/32/64) are multiples of 4 → clean hex alignment.
Why it exists
- Root cause: choosing a base that is a power of two makes binary↔base mapping a pure regrouping.