We write numbers in base 10: $2024$ means $2 \cdot 10^{3} + 0 \cdot 10^{2} + 2 \cdot 10 + 4$. Nothing is special about ten except our fingers. Computers use base 2, programmers use base 16, and the division algorithm is exactly the tool for moving between bases.
Base $b$. Fix an integer $b \ge 2$. Every positive integer $n$ can be written in exactly one way as $$n = d_k b^{k} + d_{k-1} b^{k-1} + \cdots + d_1 b + d_0,$$ with digits $0 \le d_i \le b - 1$ and $d_k \neq 0$. We write $n = (d_k d_{k-1} \dots d_0)_b$, or $d_k \dots d_0$ with a subscript $b$. Base 16 needs six extra digits: A = 10, B = 11, …, F = 15.
Why it works
Worked example: Decimal to binary
- $44 = 2 \cdot 22 + 0$
- $22 = 2 \cdot 11 + 0$
- $11 = 2 \cdot 5 + 1$
- $5 = 2 \cdot 2 + 1$
- $2 = 2 \cdot 1 + 0$, and $1 = 2 \cdot 0 + 1$. Stop when the quotient is $0$.
- The remainders were $0, 0, 1, 1, 0, 1$. Read them from the last to the first: $101100$.
- Check: $1 \cdot 32 + 0 \cdot 16 + 1 \cdot 8 + 1 \cdot 4 + 0 \cdot 2 + 0 = 44$.
Answer: $44 = 101100_2$.
Worked example: Decimal to base 7
- $2024 = 7 \cdot 289 + 1$
- $289 = 7 \cdot 41 + 2$
- $41 = 7 \cdot 5 + 6$
- $5 = 7 \cdot 0 + 5$
- Read the remainders upward: $5621_7$. Check: $5 \cdot 343 + 6 \cdot 49 + 2 \cdot 7 + 1 = 1715 + 294 + 14 + 1 = 2024$.
Answer: $2024 = 5621_7$.
Worked example: Hexadecimal to decimal
- The digits are $2$, $\mathrm{F} = 15$ and $3$, standing for $16^{2}$, $16^{1}$ and $16^{0}$.
- $2 \cdot 256 + 15 \cdot 16 + 3 = 512 + 240 + 3 = 755$.
Answer: $755$.
| Power of 2 | $2^{0}$ | $2^{1}$ | $2^{2}$ | $2^{3}$ | $2^{4}$ | $2^{5}$ | $2^{6}$ | $2^{7}$ |
|---|---|---|---|---|---|---|---|---|
| Value | 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 |
Common mistake
Base 16 is popular because it is a shorthand for base 2: split the binary digits into groups of four from the right and replace each group by one hex digit. For example $101100_2 = 0010\ 1100_2 = \mathrm{2C}_{16}$, since $0010_2 = 2$ and $1100_2 = 12 = \mathrm{C}$. Check: $2 \cdot 16 + 12 = 44$.
Binary will come back in fast powers, where the binary digits of an exponent tell you which squares to multiply.
Key idea