Number systems and conversions
Counting in 0s and 1s
- Deep down, a computer only stores 0s and 1s.
- To work with it we use three number systems — and switch between them.
- Master the conversions and the rest of data representation falls into place.
The three number systems
- Denary (base 10) — digits 0–9; the everyday system.
- Binary (base 2) — digits 0 and 1. A bit is one digit; 8 bits = 1 byte; 4 bits = 1 nibble.
- Hexadecimal (base 16) — digits 0–9 then A–F (for 10–15). One hex digit = exactly 4 bits.
| Denary | Binary | Hex |
|---|---|---|
| 10 | 1010 |
A |
| 15 | 1111 |
F |
| 16 | 1 0000 |
10 |
| 255 | 1111 1111 |
FF |
Practice
How many bits does one hexadecimal digit represent?
One hex digit (0–F) covers 16 values = $2^4$, so it maps to exactly 4 bits (a nibble).
Practice
How many bits are in one byte?
A byte is 8 bits (and a nibble is 4 bits).
Denary → binary
- Subtract the largest place value (power of 2) that fits, and repeat.
- Place values: $128, 64, 32, 16, 8, 4, 2, 1$.
- Worked: $42 = 32 + 8 + 2$ → put a 1 under those columns →
0010 1010. - Or: keep dividing by 2, record the remainders, and read them bottom-up.
Practice
Convert denary $13$ to binary (8-bit not required — just the significant bits).
$13 = 8 + 4 + 1$, so the columns 8, 4, 1 are set: 1101.
Practice
Convert binary 00101010 to denary.
$32 + 8 + 2 = 42$ (the 32, 8 and 2 columns are set).
Binary ↔ hex, and hex → denary
- Binary → hex: split the bits into nibbles (4 bits) from the right, convert each.
0010 1010→2 A→2A. - Hex → binary: replace each hex digit with its 4-bit pattern.
- Hex → denary: multiply each digit by its place value.
2E$= 2 \times 16 + 14 = 46$.
Practice
Convert hexadecimal 2E to denary.
$2 \times 16 + 14 = 32 + 14 = 46$ (E is 14).
Decimal vs binary prefixes
- Decimal prefixes (drives, network speeds): kilo $=10^3$, mega $=10^6$, giga $=10^9$, tera $=10^{12}$.
- Binary prefixes (memory sizes): kibi $=2^{10}=1024$, mebi $=2^{20}$, gibi $=2^{30}$, tebi $=2^{40}$.
- So a "1 TB" drive holds $10^{12}$ bytes, but an OS reporting in TiB ($2^{40}$) shows a smaller number.
Practice
How many bytes are in 1 kibibyte (KiB)?
A kibibyte is $2^{10} = 1024$ bytes (a binary prefix, used for memory).
You've got it
Key idea
- binary base 2 (bit · byte = 8 bits · nibble = 4 bits); hex base 16, one digit = 4 bits
- denary → binary: subtract powers of 2, or divide by 2 and read remainders bottom-up
- binary → hex by grouping nibbles; hex → denary by place value
- memory uses binary prefixes (kibi $=1024$), drives use decimal (kilo $=1000$)