Lecture 21: Division and number bases

Notes on Notation

Euclidean division

Claim (the Euclidean Division Algorithm): For any a, and any b ≠ 0, there exists integers q and r with 0 ≤ r < b and a = qb + r. Moreover, q and r are unique.

Notation: q is called the quotient of a by b, and r is called the remainder. They are written quot(a, b) and rem(a, b) respectively.

Proof (existence): We prove this only for a ≥ 0 and b > 0. You can prove the negative cases by using the existence in the positive cases.

Proof is by induction on a. Let P(a) be the statement that for all b > 0, there exists q, r as in the statement above.

To prove P(0), choose q = r = 0.

To prove P(a + 1), assume P(a). Then we know a = qb + r for some q and r. Then a + 1 = qb + (r′+1). If r′<b − 1 then r′+1 < b, so we can choose q = q and r = r′+1, which gives a = qb + r.

However, if r′=b − 1, then this choice of r doesn't satisfy the requirements of the theorem. In this case, though, we have a + 1 = qb + b = (q′+1)b + 0. Thus choosing q = q′+1 and r = 0 yields a = qb + r as required.

Proof (uniqueness): To show uniqueness, we must show that if a = qb + r and a = qb + r (with both r and r in the range [0, b)), then q = q and r = r.

Suppose that qb + r = qb + r. Then we have r − r′=(q′−q)b (). Now, we know 0 ≤ r < b and b < −r′≤0. Adding these equations yields b < r − r′<b. But we also know that r − r is a multiple of b by (), so r − r could be (for example) −2b, b, 0, b, 2b, etc. But the only multiple of b between b and b is 0, so r − r must be 0. Thus r = r.

Plugging this in to equation (*), we see that (q′−q)b = 0. Since b > 0, we have that q′−q = 0, so q = q, as required.

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 a and b ≥ 2, you can write a in base b. That is, there are digits d0, d1, ..., dn such that (dndn − 1...d2d1d0)b = a.

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 a. In the base case, we can choose di = 0. Then since b > 1, b > d0, and a = d0 = (d0)b.

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

It turns out that these digits of q are also the higher digits of a. That is, d1 = d0 and d2 = d1 and so on. To check this, we know:

$$q = \sum_{i=0}^l d_i'b^i$$

We also know that a = qb + r, so

$$a = qb + r = b(\sum_{i=0}^l d_i'b^i) + r = d_0 + \sum_{i=0}^l d_i'b^{i+1} = d_0 + \sum_{i=0}^l d_{i+1}b^{i+1}$$

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

$$a = d_0 + \sum_{j=1}^{l+1} d_jb^j = \sum_{j=0}^{l+1} d_jb^j$$

which shows that (di) 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.