Base b representation

Working in base b

Base b representation is a way to write numbers using the digits {0, 1, …, (b − 1)}.

Common bases:

A string of digits in base b, written (anan − 1. . . a3a2a1a0)b, represents the number a0b0 + a1b1 + a2b2 + ⋯ + anbn.

Arithmetic in base b

There are two ways to work with numbers in base b. The hard way: convert to base 10, apply the algorithms you already know for addition and multiplication, convert back.

The easy way: use the algorithms you already know for addition, multiplication, division, but remember that (10)b stands for b and not 10.

We did examples with long addition. Long multiplication and division work the same way.

Writing a number in base b

Theorem: for any n ≥ 1 and b ≥ 2, you can write n in base b. That is, there are digits a0, a1, ..., ak such that (akak − 1. . . a2a1a0)b = n.

Note: as with the division algorithm, the proof of this theorem contains the algorithm used to construct the base-b representation.

Proof: by strong induction on n. In the base case, we can choose a0 = 1. Then since b > 1, b > a0, and n = a0 = (a0)b.

For the inductive step, assume that any number k < n can be written in base b. We wish to write n in base b. To do so, use Euclidean division to write n = qb + r. Let a0 = r. By the inductive hypothesis, we can write q in base b: q = (alʹal − 1ʹ. . . a2ʹa1ʹa0ʹ) (we have to check that q < n, but this is true).

It turns out that these digits of q are also the higher digits of n. That is, a1 = aʹ0 and a2 = aʹ1 and so on. To check this, we know:

q = ∑ i = 0laiʹbi

We also know that n = qb + r, so

n = qb + r = b(∑ i = 0laiʹbi) + r = a0 + ∑ i = 0laiʹbi + 1 = a0 + ∑ i = 0lai + 1bi + 1

By changing i to k − 1 in the summation this becomes

n = a0 + ∑ k = 1l + 1akbk = ∑ k = 0l + 1akbk

which shows that (ai) is the base b representation of n.

Note: we stated (but did not prove) that the base b representation is unique (just as quotient and remainder are), this is a good exercise. It follows directly from the uniqueness of the quotient and remainder.