- Interpreting a string of digits in base
*b* - Every number can be written uniquely in any base
- Converting to base
*b*

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

Common bases:

you use base 10 (

**decimal**) every day (digits are {0, 1, . . . , 9})base 2 (

**binary**) uses digits {0, 1}. It is convenient for digital logic, a digit (called a**bit**) can be represented using a single wire: the wire has high voltage for 1, low for 0. Binary numbers are often designated by a trailing b: for example 1101b.base 16 (

**hexadecimal**) uses the digits {0, 1, 2, . . . , 9,*A*,*B*,*C*,*D*,*E*,*F*}. it is useful becausee a single digit can be represented using 4 bits. Hex numbers are often written with a prefix of "0x": for example 0xFC39.base 8 (

**octal**) uses the digits {0, 1, 2, . . . , 7}, and is occasionally used when 3-bit numbers are useful.

A string of digits in base *b*, written (*a*_{n}*a*_{n − 1}. . . *a*_{3}*a*_{2}*a*_{1}*a*_{0})_{b}, represents the number *a*_{0}*b*^{0} + *a*_{1}*b*^{1} + *a*_{2}*b*^{2} + ⋯ + *a*_{n}*b*^{n}.

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.

**Theorem**: for any *n* ≥ 1 and *b* ≥ 2, you can write *n* in base *b*. That is, there are digits *a*_{0}, *a*_{1}, ..., *a*_{k} such that (*a*_{k}*a*_{k − 1}. . . *a*_{2}*a*_{1}*a*_{0})_{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 *a*_{0} = 1. Then since *b* > 1, *b* > *a*_{0}, and *n* = *a*_{0} = (*a*_{0})_{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* = *q**b* + *r*. Let *a*_{0} = *r*. By the inductive hypothesis, we can write *q* in base *b*: *q* = (*a*_{l}ʹ*a*_{l − 1}ʹ. . . *a*_{2}ʹ*a*_{1}ʹ*a*_{0}ʹ) (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, *a*_{1} = *a*ʹ_{0} and *a*_{2} = *a*ʹ_{1} and so on. To check this, we know:

*q* = ∑ _{i = 0}^{l}*a*_{i}ʹ*b*^{i}

We also know that *n* = *q**b* + *r*, so

*n* = *q**b* + *r* = *b*(∑ _{i = 0}^{l}*a*_{i}ʹ*b*^{i}) + *r* = *a*_{0} + ∑ _{i = 0}^{l}*a*_{i}ʹ*b*^{i + 1} = *a*_{0} + ∑ _{i = 0}^{l}*a*_{i + 1}*b*^{i + 1}

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

*n* = *a*_{0} + ∑ _{k = 1}^{l + 1}*a*_{k}*b*^{k} = ∑ _{k = 0}^{l + 1}*a*_{k}*b*^{k}

which shows that (*a*_{i}) 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.