Sub topic 4
From Decimal to Base \(n\) by Repeated Division
Assume you can divide whole numbers with remainders, use powers of 2, 3, and 10, and read positional notation. The goal is to write a decimal integer using powers of a chosen base.
The repeated-division method
To convert a decimal number \(N\) to base \(b\):
- Divide \(N\) by \(b\).
- Record the remainder.
- Divide the quotient by \(b\).
- Continue until the quotient is 0.
- Read the remainders from bottom to top.
The remainder is always one of \(0,1,\ldots,b-1\), so it becomes a valid digit in base \(b\).
For bases above 10, use letters for values 10 through 15:
| Value | Base-16 digit |
|---|---|
| 10 | A |
| 11 | B |
| 12 | C |
| 13 | D |
| 14 | E |
| 15 | F |
Worked example: \(45_{10}\) in base 2
| Division | Quotient | Remainder |
|---|---|---|
| \(45 \div 2\) | 22 | 1 |
| \(22 \div 2\) | 11 | 0 |
| \(11 \div 2\) | 5 | 1 |
| \(5 \div 2\) | 2 | 1 |
| \(2 \div 2\) | 1 | 0 |
| \(1 \div 2\) | 0 | 1 |
Reading the remainders upward gives
\[ 45{10}=1011012. \]
Check the result using place value:
\[ 101101_2=1(2^5)+0(2^4)+1(2^3)+1(2^2)+0(2^1)+1 =32+8+4+1=45. \]
A second example
Convert \(58_{10}\) to base 5:
\[ 58=5(11)+3 \] \[ 11=5(2)+1 \] \[ 2=5(0)+2 \]
The remainders are \(3,1,2\). Reading upward gives
\[ 58{10}=2135. \]
Verify:
\[ 213_5=2(5^2)+1(5)+3=50+5+3=58. \]
The method works because each division separates the number into a multiple of the base and a remainder:
\[ N=bq+r. \]
The remainder \(r\) is the rightmost digit. Repeating the process finds the next digit to its left.
Using a program to reduce arithmetic errors
def to_base(n, base):
symbols = "0123456789ABCDEF"
if n == 0:
return "0"
out = []
while n > 0:
n, r = divmod(n, base)
out.append(symbols[r])
return "".join(reversed(out))
print(to_base(45, 2)) # 101101
print(to_base(45, 16)) # 2DThe function stores remainders in reverse order, then reverses the list before joining the digits. For CAT questions, perform the divisions by hand first. Use place-value expansion or a size estimate to check the result.
Exercise
Convert \(156_{10}\) to base 7 and verify your answer.
Show answer
\(156=7(22)+2\), \(22=7(3)+1\), and \(3=7(0)+3\). Reading upward gives \(312_7\). Check: \(3(49)+1(7)+2=156\).