MATH2400 2,833 words·15 min read

Base Number Systems

Introduction to Base Number Systems#

A base is a natural number B whose powers (B multiplied by itself some number of times) are specially designated within a numerical system

The Base 10 Number System

  • Also called the decimal system
  • Represents numbers using ten digits; 0,1,2,3,4,5,6,7,8,9;
  • Multiplies each digit by a power of 10 based on its position

1234=(1×103)+(2×102)+(3×101)+(4×100).1234 = (1\times 10^3) + (2 \times 10^2) + (3 \times 10^1) + (4\times 10^0).

Some numbers have two representations in base 10, i.e.

x=0.9‾10x=9.9‾10x=9+0.9‾10x=9+x9x=9x=1\begin{align*} x&=0.\overline{9} \\ 10x &= 9.\overline{9} \\ 10x &= 9 + 0.\overline{9} \\ 10x &= 9 + x \\ 9x &= 9 \\ x &= 1 \end{align*}

Here, xx represents both 0.9‾0.\overline{9} and 11.

Note

Definition 2.1
For any integer b≥2b \geq 2, the base bb representation of the number α∈R+\alpha \in \mathbb{R}^+ is written as the digit string

(dndn−1⋯d1d0.d−1d−2⋯ )b,(d_n d_{n-1} \cdots d_1 d_0 . d_{-1} d_{-2} \cdots)_b,

for some n∈Nn \in \mathbb{N}, where

α=dn×bn+dn−1×bn−1+⋯+d1×b1+d0×b0+d−1×b−1+d−2×b−2+⋯\alpha = d_n \times b^n + d_{n-1} \times b^{n-1} + \cdots + d_1 \times b^1 + d_0 \times b^0 + d_{-1} \times b^{-1} + d_{-2} \times b^{-2} + \cdots

and for each digit did_i we have that di∈{0,1,2,…,b−1}d_i \in \{0, 1, 2, \dots, b - 1\} with dn>0d_n > 0.
Furthermore, for all k∈Z+k \in \mathbb{Z}^+, we require that

(d−k,d−k−1,d−k−2,… )b≠(b−1,b−1,b−1,… )b.(d_{-k}, d_{-k-1}, d_{-k-2}, \dots)_b \neq (b - 1, b - 1, b - 1, \dots)_b.

Basically, base bb works exactly like the decimal system except that each position now scales by a power of bb instead of a power of 1010, and the only digits allowed are 00 up to b−1b-1. Negative numbers are handled by simply putting a negative sign at the front of the digit string, and we omit writing infinitely many trailing zeros past the radix point; we write 1010 rather than 10.000…10.000\dots

The final condition in the definition bans digit strings that end in the digit b−1b-1 repeating forever. This is exactly the base bb version of the 0.9‾=10.\overline{9}=1 situation from above; without this condition, some numbers would have two different representations and the notation would be ambiguous.

Example. Show that (0.(b−1)‾)b=1(0.\overline{(b-1)})_b = 1 in every base b≥2b \geq 2.
Let x=(0.(b−1)‾)bx = (0.\overline{(b-1)})_b. Multiplying by bb shifts the radix point one place to the right, so

bx=((b−1).(b−1)‾)bbx=(b−1)+xbx−x=b−1(b−1)x=b−1x=1.\begin{align*} bx &= ((b-1).\overline{(b-1)})_b \\ bx &= (b-1) + x \\ bx - x &= b-1 \\ (b-1)x &= b-1 \\ x &= 1. \end{align*}

Therefore, (0.7‾)8=1(0.\overline{7})_8 = 1, (0.4‾)5=1(0.\overline{4})_5 = 1, (0.1‾)2=1(0.\overline{1})_2 = 1, and so on; the 0.9‾0.\overline{9} trick was never really about 1010 at all.

When writing numbers in different bases, we should always include the base as a subscript, except in base 10 where it is standard to omit it. In bases greater than 1010 we run out of ordinary digits, so any digit larger than 99 is surrounded with brackets, e.g. (9(15)(33))60(9(15)(33))_{60}. In some bases such as base 16 (hexadecimal), it is instead standard to use capital letters as the new digits.

Example. Convert (DAB)16(DAB)_{16} to a decimal (base 10) number.
Here, each digit represents the following;
A=10,B=11,C=12,D=13⋯F=15A=10,B=11,C=12,D=13 \cdots F=15, therefore,

(DAB)16=(13×162)+(10×161)+(11×160)=3328+160+11=3499\begin{align*} (DAB)_{16} &= (13\times16^2) + (10\times16^1) + (11 \times 16^0) \\ &= 3328+160+11 \\ &= 3499 \end{align*}

Example. Convert (1234)5(1234)_5 to a decimal number.
Each digit gets multiplied by the power of 55 determined by its position;

(1234)5=(1×53)+(2×52)+(3×51)+(4×50)=125+50+15+4=194.\begin{align*} (1234)_5 &= (1\times 5^3) + (2 \times 5^2) + (3 \times 5^1) + (4 \times 5^0) \\ &= 125 + 50 + 15 + 4 \\ &= 194. \end{align*}

Therefore, (1234)5=194(1234)_5 = 194.

Example. Convert (9(15)(33))60(9(15)(33))_{60} to a decimal number.
Base 60 needs sixty different digits, so the digits 1515 and 3333 are written in brackets. The digit string here is 9,15,339, 15, 33, and each digit is multiplied by a power of 6060;

(9(15)(33))60=(9×602)+(15×601)+(33×600)=32400+900+33=33333.\begin{align*} (9(15)(33))_{60} &= (9 \times 60^2) + (15 \times 60^1) + (33 \times 60^0) \\ &= 32400 + 900 + 33 \\ &= 33333. \end{align*}

Therefore, (9(15)(33))60=33333(9(15)(33))_{60} = 33333. Do not read (9(15)(33))60(9(15)(33))_{60} as the digit string 9,1,5,3,39,1,5,3,3; each bracketed block is one single digit.

Example. Convert (101.0101)2(101.0101)_2 to a decimal number.
Digits after the radix point are multiplied by negative powers of the base;

(101.0101)2=(1×22)+(0×21)+(1×20)+(0×2−1)+(1×2−2)+(0×2−3)+(1×2−4)=4+1+14+116=5+516=8516.\begin{align*} (101.0101)_2 &= (1 \times 2^2) + (0 \times 2^1) + (1 \times 2^0) + (0 \times 2^{-1}) + (1 \times 2^{-2}) + (0 \times 2^{-3}) + (1 \times 2^{-4}) \\ &= 4 + 1 + \frac{1}{4} + \frac{1}{16} \\ &= 5 + \frac{5}{16} \\ &= \frac{85}{16}. \end{align*}

Therefore, (101.0101)2=8516=5.3125(101.0101)_2 = \frac{85}{16} = 5.3125.

Converting Non-Decimal Numbers to Decimal#

Note

Definition 2.2
A terminating base representation is one that ends in infinitely many trailing zeros. A terminating base bb representation of a number can be written in the form:

(dndn−1⋯d1d0.d−1d−2d−3…d−k)b,(d_n d_{n-1} \cdots d_1 d_0 . d_{-1} d_{-2} d_{-3} \dots d_{-k})_b,

for some natural numbers nn and kk.

Note

Definition 2.3
A periodic (or recurring or eventually periodic) base representation is one for which some finite string of digits (which are not all 0) repeats itself indefinitely after the radix point.

Note

Notation
We indicate the periodic part of a periodic base representation by writing a horizontal bar over the top of the repeating digit string. For example, (0.123‾)4=(0.123123123… )4(0.\overline{123})_4 = (0.123123123\dots)_4, and (0.1234‾)6=(0.12343434… )6(0.12\overline{34})_6 = (0.12343434\dots)_6.

Note

Definition 2.4
A non-periodic base representation is one that is neither terminating nor periodic.

Basically, every base representation falls into exactly one of three buckets: it either stops (terminating), eventually falls into a repeating cycle (periodic), or does neither (non-periodic). Which bucket a number lands in tells us something about the number itself:

Note

Theorem
A real number α\alpha is rational if and only if its expansion in any base is either terminating or periodic. Equivalently, a real number α\alpha is irrational if and only if its expansion in any base is non-periodic.

Notice how the theorem says any base; rationality is a property of the number, not of the representation. So 2\sqrt{2} and π\pi have non-periodic expansions in base 2, base 7, base 16 — every base. The reason this works is the conversion algorithm later in these notes: when converting a rational number, the remainder at each step can only take finitely many values, so eventually a remainder must repeat (basically the pigeonhole principle), which forces the digits into a cycle.

We can even predict which rationals terminate and which recur, before doing any actual converting:

Note

Terminating Criterion
Let b≥2b \geq 2 be an integer and let α=pq∈Q+\alpha = \frac{p}{q} \in \mathbb{Q}^+ with gcd⁡(p,q)=1\gcd(p,q)=1. Then the base bb representation of α\alpha terminates if and only if every prime factor of qq also divides bb (equivalently, q∣bnq \mid b^n for some n∈Nn \in \mathbb{N}).

Basically, a terminating representation is just a fraction of the form mbn\frac{m}{b^n}, and pq\frac{p}{q} can be rewritten in that form precisely when all of qq's prime factors already appear in bb.

Example. Without converting, decide whether each of the following terminates or recurs: 38\frac{3}{8} in base 6, 2435\frac{24}{35} in base 5, and 15\frac{1}{5} in base 2.

  • For 38\frac{3}{8} in base 6: q=8=23q = 8 = 2^3, whose only prime factor is 22, and 2∣62 \mid 6; the representation terminates.
  • For 2435\frac{24}{35} in base 5: q=35=5×7q = 35 = 5 \times 7, and 7∤57 \nmid 5; the representation is periodic.
  • For 15\frac{1}{5} in base 2: q=5q = 5, and 5∤25 \nmid 2; the representation is periodic.

Therefore whether a rational terminates depends on the base; 15=0.2\frac{1}{5} = 0.2 terminates in base 10 yet recurs forever in base 2. We will verify the first two of these with the conversion algorithm later.

Example. Convert (0.123‾)4(0.\overline{123})_4 to a decimal (base 10) number.
Suppose x=(0.123‾)4x = (0.\overline{123})_4, then,

(4)x=(1.231‾)4, (as multiplying a decimal by its own base shifts it 1 to the left),(42)x=(12.312‾)4(43)x=(123.123‾)4(43−1)x=(123.123‾)4−x(43−1)x=(123)4x=(123)4(43−1)10x=2763x=37.\begin{align*} (4)x &= (1.\overline{231})_4,\text{ (as multiplying a decimal by its own base shifts it 1 to the left)}, \\ (4^2)x&=(12.\overline{312})_4 \\ (4^3)x &= (123.\overline{123})_4 \\ (4^3-1)x &= (123.\overline{123})_4 - x \\ (4^3-1)x &= (123)_4 \\ x &= \frac{(123)_4}{(4^3-1)_{10}} \\ x &= \frac{27}{63} \\ x &= \frac{3}{7}. \end{align*}

This method for periodic base representations can be generalised as follows:

  • Let xx be the number in base bb representation and let kk be the period length.
  • Find bkxb^k x by shifting the radix point kk places to the right.
  • Calculate bkx−xb^k x - x to eliminate the repeating part.
  • Factorise the left-hand side and divide to get x=bkx−xbk−1x = \frac{b^k x - x}{b^k - 1} in base bb.
  • Convert the numerator and denominator to decimal forms and simplify the fraction if necessary.

Example. Express y=(0.1234‾)6y=(0.12\overline{34})_6 as a decimal fraction.
Here, b=6b=6, k=2k=2, so the answer would be

(12.3434‾)6−(0.1234‾)6(62−1)10\frac{(12.34\overline{34})_6 - (0.12\overline{34})_6}{(6^2 - 1)_{10}}

In the numerator, the recurring part cancels out after the radix point to only leave 34−1234-12 which is 2222, meaning we get

(12.22)6(62−1)10\frac{(12.22)_6}{(6^2-1)_{10}}

or

y=15163010.y=\frac{151}{630}_{10}.

Doing this the normal way would be:
Suppose x=(0.1234‾)6x = (0.12\overline{34})_6, then,

62x=(12.34‾)662x−1x=(12.3434‾−0.1234‾)6(62−1)x=12.226x=12.22662−1x=1511862−1x=1511835x=151630\begin{align*} 6^2 x&=(12.\overline{34})_6 \\ 6^2x - 1x&=(12.34\overline{34}-0.12\overline{34})_6 \\ (6^2-1)x&=12.22_6 \\ x &= \frac{12.22_6}{6^2-1} \\ x &= \frac{\frac{151}{18}}{6^2-1} \\ x &= \frac{\frac{151}{18}}{35} \\ x &= \frac{151}{630} \end{align*}

The Geometric Series Method#

Alternatively, we can convert a periodic representation to a decimal fraction using the formula for an infinite geometric series. Recall that for any real rr with 0≤∣r∣<10 \leq |r| < 1,

∑k=1∞rk=r1−r.\boxed{\sum_{k=1}^{\infty} r^k = \frac{r}{1-r}.}

The idea is to treat each copy of the repeating block as one term of a geometric series, since every copy is bkb^k times smaller than the copy before it, where kk is the period length. The derivation of this formula is first year stuff so I'm not writing it out.

Example. Write (0.123‾)4(0.\overline{123})_4 as a decimal fraction using the geometric series formula.
The repeating block is worth (123)4=1×42+2×4+3=27(123)_4 = 1 \times 4^2 + 2 \times 4 + 3 = 27, and the first copy of the block sits in the first three places after the radix point, so it is worth 2743\frac{27}{4^3}; every later copy is 43=644^3 = 64 times smaller than the one before it. Hence,

(0.123‾)4=2743+2746+2749+⋯=27∑k=1∞(164)k=27×1641−164=27×163=37.\begin{align*} (0.\overline{123})_4 &= \frac{27}{4^3} + \frac{27}{4^6} + \frac{27}{4^9} + \cdots \\ &= 27\sum_{k=1}^{\infty}\left( \frac{1}{64} \right)^k \\ &= 27 \times \frac{\frac{1}{64}}{1-\frac{1}{64}} \\ &= 27 \times \frac{1}{63} \\ &= \frac{3}{7}. \end{align*}

Therefore, (0.123‾)4=37(0.\overline{123})_4 = \frac{3}{7}, agreeing with the shifting method from before.

Example. Write (0.1234‾)6(0.12\overline{34})_6 as a decimal fraction using the geometric series formula.
Split the number into its non-repeating head and its repeating tail. The head is

(0.12)6=16+236=836=29,\begin{align*} (0.12)_6 &= \frac{1}{6} + \frac{2}{36} \\ &= \frac{8}{36} \\ &= \frac{2}{9}, \end{align*}

and the tail is made of copies of the block (34)6=3×6+4=22(34)_6 = 3 \times 6 + 4 = 22, where the first copy ends four places after the radix point (so it is worth 2264\frac{22}{6^4}) and each later copy is 62=366^2 = 36 times smaller;

(0.0034‾)6=2264+2266+2268+⋯=2262∑k=1∞(136)k=2236×1361−136=2236×135=11630.\begin{align*} (0.00\overline{34})_6 &= \frac{22}{6^4} + \frac{22}{6^6} + \frac{22}{6^8} + \cdots \\ &= \frac{22}{6^2} \sum_{k=1}^{\infty} \left( \frac{1}{36} \right)^k \\ &= \frac{22}{36} \times \frac{\frac{1}{36}}{1 - \frac{1}{36}} \\ &= \frac{22}{36} \times \frac{1}{35} \\ &= \frac{11}{630}. \end{align*}

Adding the two parts together,

(0.1234‾)6=29+11630=140630+11630=151630,\begin{align*} (0.12\overline{34})_6 &= \frac{2}{9} + \frac{11}{630} \\ &= \frac{140}{630} + \frac{11}{630} \\ &= \frac{151}{630}, \end{align*}

which matches the shifting method. In general, use the shifting method when the digit subtraction bkx−xb^kx - x is easy to do, and the geometric series when you would rather work with plain fractions from the start.

Example. Convert the repeating binary number (0.0011‾)2(0.\overline{0011})_2 to a fraction.
The period starts immediately after the radix point, so the shortcut x=bkx−xbk−1x = \frac{b^kx - x}{b^k - 1} applies directly with b=2b = 2 and k=4k = 4;

x=(0011)2(24−1)10=315=15.\begin{align*} x &= \frac{(0011)_2}{(2^4-1)_{10}} \\ &= \frac{3}{15} \\ &= \frac{1}{5}. \end{align*}

Therefore, (0.0011‾)2=15(0.\overline{0011})_2 = \frac{1}{5}. Notice how 15\frac{1}{5} terminates in base 10 but recurs in base 2, since 5∤25 \nmid 2, exactly as the terminating criterion predicted; this is basically why computers, which store numbers in binary, can never represent 0.20.2 exactly.

A Base Conversion Algorithm#

Note

Theorem
For any α∈R\alpha \in \mathbb{R} and integer b≥2b \geq 2, the base bb representation of α\alpha as defined in Definition 2.1 is unique.

The naive way to convert some α∈R+\alpha \in \mathbb{R}^+ into base bb would be to find the largest power bkb^k that does not exceed α\alpha, take the largest multiple of bkb^k that still fits (giving the leading digit), subtract it off, and repeat on whatever is left over. This works, but it has two problems:

  • you need to know (or compute) all of the positive and negative powers of bb before you can even start; and
  • if the expansion turns out to be periodic, you can never be sure when the periodic part begins and ends.

The following algorithm avoids both of these problems.

To convert a decimal number α∈R+\alpha \in \mathbb{R}^+ to some other base bb, we use two algorithms,

  • one for the integer part ⌊α⌋\lfloor \alpha \rfloor; and
  • one for the fractional part {α}\{\alpha\}.

Integer Part: Use the division algorithm to find quotients qiq_i and remainders did_i when dividing by bb iteratively.

⌊α⌋=q0×b+d0where q0,d0∈Z,0≤d0<bq0=q1×b+d1where q1,d1∈Z,0≤d1<bq1=q2×b+d2where q2,d2∈Z,0≤d2<b    ⋮    ⋮qn−2=qn−1×b+dn−1where qn−1,dn−1∈Z,0≤dn−1<bqn−1=0×b+dnwhere dn∈Z,0≤dn<b\begin{aligned} \lfloor \alpha \rfloor &= q_0 \times b + d_0 && \text{where } q_0, d_0 \in \mathbb{Z}, 0 \leq d_0 < b \\ q_0 &= q_1 \times b + d_1 && \text{where } q_1, d_1 \in \mathbb{Z}, 0 \leq d_1 < b \\ q_1 &= q_2 \times b + d_2 && \text{where } q_2, d_2 \in \mathbb{Z}, 0 \leq d_2 < b \\ &\;\;\vdots && \;\;\vdots \\ q_{n-2} &= q_{n-1} \times b + d_{n-1} && \text{where } q_{n-1}, d_{n-1} \in \mathbb{Z}, 0 \leq d_{n-1} < b \\ q_{n-1} &= 0 \times b + d_n && \text{where } d_n \in \mathbb{Z}, 0 \leq d_n < b \end{aligned}

The remainders from each step form the digits of the integer part of α\alpha in reverse. That is,

⌊α⌋=(dndn−1…d2d1d0)b.\lfloor \alpha \rfloor = (d_n d_{n-1} \dots d_2 d_1 d_0)_b.

Fractional part: Set r0={α}=α−⌊α⌋r_0 = \{\alpha\} = \alpha - \lfloor \alpha \rfloor and iteratively multiply ri−1r_{i-1} by bb, writing the result as a sum of its integer part d−id_{-i} and its fractional part rir_i:

b×r0=d−1+r1where d−1=⌊b×r0⌋ and r1={b×r0},b×r1=d−2+r2where d−2=⌊b×r1⌋ and r2={b×r1},    ⋮    ⋮b×rn−1=d−n+rnwhere d−n=⌊b×rn−1⌋ and rn={b×rn−1},\begin{aligned} b \times r_0 &= d_{-1} + r_1 && \text{where } d_{-1} = \lfloor b \times r_0 \rfloor \text{ and } r_1 = \{b \times r_0\}, \\ b \times r_1 &= d_{-2} + r_2 && \text{where } d_{-2} = \lfloor b \times r_1 \rfloor \text{ and } r_2 = \{b \times r_1\}, \\ &\;\;\vdots && \;\;\vdots \\ b \times r_{n-1} &= d_{-n} + r_n && \text{where } d_{-n} = \lfloor b \times r_{n-1} \rfloor \text{ and } r_n = \{b \times r_{n-1}\}, \end{aligned}

and if α\alpha is rational then the process will terminate at the nnth step, when either:

  • rn=0r_n = 0, so {α}=(0.d−1d−2…d−n)b\{\alpha\} = (0.d_{-1}d_{-2} \dots d_{-n})_b; or
  • rn=rkr_n = r_k for some k<nk < n, in which case the expansion is periodic, and {α}=(0.d−1d−2…d−kd−(k+1)…d−n‾)b\{\alpha\} = (0.d_{-1}d_{-2} \dots d_{-k}\overline{d_{-(k+1)} \dots d_{-n}})_b.

Remember that the integer part digits come out in reverse order (last remainder first), whilst the fractional part digits come out in forwards order.

Example. Write 3579383579 \frac{3}{8} in base 6.

To convert α=357938\alpha = 3579 \frac{3}{8} to base b=6b=6, we split the number into its integer part ⌊α⌋=3579\lfloor \alpha \rfloor = 3579 and its fractional part {α}=38\{\alpha\} = \frac{3}{8}, and apply the two algorithms.

Integer Part: Use the division algorithm to find quotients qiq_i and remainders did_i when dividing by 66 iteratively.

3579=596×6+3where q0=596,d0=3596=99×6+2where q1=99,d1=299=16×6+3where q2=16,d2=316=2×6+4where q3=2,d3=42=0×6+2where q4=0,d4=2\begin{aligned} 3579 &= 596 \times 6 + 3 && \text{where } q_0=596, d_0 = 3 \\ 596 &= 99 \times 6 + 2 && \text{where } q_1=99, d_1 = 2 \\ 99 &= 16 \times 6 + 3 && \text{where } q_2=16, d_2 = 3 \\ 16 &= 2 \times 6 + 4 && \text{where } q_3=2, d_3 = 4 \\ 2 &= 0 \times 6 + 2 && \text{where } q_4=0, d_4 = 2 \end{aligned}

The remainders from each step form the digits of the integer part of α\alpha in reverse. That is,

⌊α⌋=(24323)6.\lfloor \alpha \rfloor = (24323)_6.

Fractional part: Set r0={α}=38r_0 = \{\alpha\} = \frac{3}{8} and iteratively multiply ri−1r_{i-1} by 66, writing the result as a sum of its integer part d−id_{-i} and its fractional part rir_i:

6×38=94=2+14where d−1=2 and r1=14,6×14=32=1+12where d−2=1 and r2=12,6×12=3=3+0where d−3=3 and r3=0\begin{aligned} 6 \times \frac{3}{8} = \frac{9}{4} &= 2 + \frac{1}{4} && \text{where } d_{-1} = 2 \text{ and } r_1 = \frac{1}{4}, \\ 6 \times \frac{1}{4} = \frac{3}{2} &= 1 + \frac{1}{2} && \text{where } d_{-2} = 1 \text{ and } r_2 = \frac{1}{2}, \\ 6 \times \frac{1}{2} = 3 &= 3 + 0 && \text{where } d_{-3} = 3 \text{ and } r_3 = 0 \end{aligned}

Because r3=0r_3 = 0, the process terminates at the 33rd step. So,

{α}=(0.213)6\{\alpha\} = (0.213)_6

Combining the integer and fractional parts gives the final unique representation:

357938=(24323.213)63579 \frac{3}{8} = (24323.213)_6

Notice that 8=238 = 2^3 and 2∣62 \mid 6, so the terminating criterion knew this fractional part would terminate before we ran a single step.

Example. Write 2435\frac{24}{35} in base 5.

Since 0<2435<10 < \frac{24}{35} < 1, there is no integer part to worry about; ⌊α⌋=0\lfloor \alpha \rfloor = 0. Also, 35=5×735 = 5 \times 7 and 7∤57 \nmid 5, so the terminating criterion warns us in advance that the expansion will be periodic; the algorithm must end with a repeated remainder rn=rkr_n = r_k rather than with rn=0r_n = 0.

Fractional part: Set r0={α}=2435r_0 = \{\alpha\} = \frac{24}{35} and iteratively multiply ri−1r_{i-1} by 55:

5×2435=247=3+37where d−1=3 and r1=37,5×37=157=2+17where d−2=2 and r2=17,5×17=57=0+57where d−3=0 and r3=57,5×57=257=3+47where d−4=3 and r4=47,5×47=207=2+67where d−5=2 and r5=67,5×67=307=4+27where d−6=4 and r6=27,5×27=107=1+37where d−7=1 and r7=37.\begin{aligned} 5 \times \frac{24}{35} = \frac{24}{7} &= 3 + \frac{3}{7} && \text{where } d_{-1} = 3 \text{ and } r_1 = \frac{3}{7}, \\ 5 \times \frac{3}{7} = \frac{15}{7} &= 2 + \frac{1}{7} && \text{where } d_{-2} = 2 \text{ and } r_2 = \frac{1}{7}, \\ 5 \times \frac{1}{7} = \frac{5}{7} &= 0 + \frac{5}{7} && \text{where } d_{-3} = 0 \text{ and } r_3 = \frac{5}{7}, \\ 5 \times \frac{5}{7} = \frac{25}{7} &= 3 + \frac{4}{7} && \text{where } d_{-4} = 3 \text{ and } r_4 = \frac{4}{7}, \\ 5 \times \frac{4}{7} = \frac{20}{7} &= 2 + \frac{6}{7} && \text{where } d_{-5} = 2 \text{ and } r_5 = \frac{6}{7}, \\ 5 \times \frac{6}{7} = \frac{30}{7} &= 4 + \frac{2}{7} && \text{where } d_{-6} = 4 \text{ and } r_6 = \frac{2}{7}, \\ 5 \times \frac{2}{7} = \frac{10}{7} &= 1 + \frac{3}{7} && \text{where } d_{-7} = 1 \text{ and } r_7 = \frac{3}{7}. \end{aligned}

Here r7=37=r1r_7 = \frac{3}{7} = r_1, so the process terminates at the 77th step with n=7n = 7 and k=1k = 1; every digit strictly after d−1d_{-1} repeats indefinitely. Therefore,

2435=(0.3203241‾)5.\frac{24}{35} = (0.3\overline{203241})_5.

Notice how after the first step every remainder is a fraction with denominator 77; there are only six possible non-zero values 17,27,…,67\frac{1}{7}, \frac{2}{7}, \dots, \frac{6}{7}, so the algorithm was always going to repeat within at most six further steps. This pigeonhole argument is exactly why rational numbers always have terminating or periodic expansions.

Example. Write 34993499 in base 16.

This is the integer part algorithm again, except now the remainders can be larger than 99, so we translate them into hexadecimal digits at the end (A=10,B=11,…,F=15A = 10, B = 11, \dots, F = 15).

3499=218×16+11where q0=218,d0=11=B218=13×16+10where q1=13,d1=10=A13=0×16+13where q2=0,d2=13=D\begin{aligned} 3499 &= 218 \times 16 + 11 && \text{where } q_0 = 218, d_0 = 11 = B \\ 218 &= 13 \times 16 + 10 && \text{where } q_1 = 13, d_1 = 10 = A \\ 13 &= 0 \times 16 + 13 && \text{where } q_2 = 0, d_2 = 13 = D \end{aligned}

Reading the remainders in reverse gives

3499=(DAB)16,3499 = (DAB)_{16},

which is exactly the number we converted in the other direction at the start of these notes; the two conversion processes undo each other. Each remainder is one single digit; a remainder of 1313 is the digit DD, not the two digits 11 and 33.

Converting Between Non-Decimal Bases#

When converting a number between two bases that share a common root, meaning both bases are powers of the same integer bb (e.g., base bmb^m and base bnb^n), we can bypass the standard base 10 conversion algorithms. Instead, we use base bb as an intermediate system.

Note

Theorem
For any integer b≥2b \geq 2 and positive integers m,nm, n, every single digit in base bmb^m corresponds uniquely to a block of exactly mm digits in base bb.

This property allows us to translate numbers by "expanding" digits into blocks or "grouping" blocks into single digits.

To convert from a larger base bmb^m to a smaller base bb, expand each individual digit of the base bmb^m number into its mm-digit representation in base bb. Padding with leading zeros is required to ensure every intermediate block has exactly mm digits.

To convert from a smaller base bb to a larger base bmb^m, group the base bb digits into blocks of length mm.

  • For the integer part ⌊α⌋\lfloor \alpha \rfloor, start at the radix point and group moving strictly to the left. Pad the leftmost block with leading zeros if necessary.
  • For the fractional part {α}\{\alpha\}, start at the radix point and group moving strictly to the right.

If a fractional part {α}\{\alpha\} is periodic in base bb with a period length of kk, and we are grouping into blocks of length mm to convert to base bmb^m, the period may not immediately align with the block size.

To find the new periodic representation, the base bb sequence must be written out until the period length kk and the block size mm perfectly synchronize. This synchronization occurs at the least common multiple (LCM) of kk and mm.

The new period length in base bmb^m will be lcm(k,m)m\frac{\text{lcm}(k, m)}{m}.

Example. Convert (34.52‾)8(34.\overline{52})_8 to base 22.

Here, we are moving from base 88 (232^3) to base 22, so b=2b=2 and m=3m=3. We expand each base 8 digit into exactly 3 base 2 digits.

Integer part:

38=011248=1002\begin{aligned} 3_8 &= 011_2 \\ 4_8 &= 100_2 \end{aligned}

Fractional part:

58=101228=0102\begin{aligned} 5_8 &= 101_2 \\ 2_8 &= 010_2 \end{aligned}

Stringing these blocks together in order yields the base 2 representation. Leading zeros on the integer part can be omitted:

(34.52‾)8=(11100.101010‾)2(34.\overline{52})_8 = (11100.\overline{101010})_2

Example. Convert (10111.0110‾)2(10111.01\overline{10})_2 to base 1616.
Here, we are moving from base 22 to base 1616 (242^4), so b=2b=2 and m=4m=4. We group the digits into blocks of 4. Standard base 16 notation applies (A=10,B=11,…,F=15A=10, B=11, \dots, F=15).

Integer part (start at radix, move left):

101112  ⟹  0001⏟1    0111⏟710111_2 \implies \underbrace{0001}_{1} \;\; \underbrace{0111}_{7}

Therefore, ⌊α⌋=(17)16\lfloor \alpha \rfloor = (17)_{16}.

Fractional part (start at radix, move right):
The fraction is 0.0110‾20.01\overline{10}_2, meaning the block 1010 repeats infinitely: 0.01101010…20.01101010\dots_2. We group these into blocks of 4 moving right:

0110⏟6    1010⏟10 (A)    1010⏟10 (A)…\underbrace{0110}_{6} \;\; \underbrace{1010}_{10 \,(A)} \;\; \underbrace{1010}_{10 \,(A)} \dots

Because the block 10101010 repeats indefinitely, the new period is simply AA.

Therefore, {α}=(0.6A‾)16\{\alpha\} = (0.6\overline{A})_{16}.

Combining both parts:

(10111.0110‾)2=(17.6A‾)16(10111.01\overline{10})_2 = (17.6\overline{A})_{16}

(Check: both sides equal 2351223\tfrac{5}{12}; note we avoid a repeating 11 on its own, since a tail of infinitely repeating b−1b-1 digits is forbidden by Definition 2.1.)

Example. Write (121.2)3(121.2)_3 in base 9.

Here 9=329 = 3^2, so b=3b = 3 and m=2m = 2; we group the base 3 digits into blocks of 22.

Integer part (start at radix, move left): the string 121121 has odd length, so the leftmost block gets padded with a leading zero,

1213  ⟹  01⏟1    21⏟7121_3 \implies \underbrace{01}_{1} \;\; \underbrace{21}_{7}

since (01)3=1(01)_3 = 1 and (21)3=2×3+1=7(21)_3 = 2 \times 3 + 1 = 7. Therefore, ⌊α⌋=(17)9\lfloor \alpha \rfloor = (17)_9.

Fractional part (start at radix, move right): the string 22 is too short for a full block, so it gets padded with a trailing zero (trailing zeros past the radix point change nothing),

23  ⟹  20⏟62_3 \implies \underbrace{20}_{6}

since (20)3=2×3+0=6(20)_3 = 2 \times 3 + 0 = 6. Therefore, {α}=(0.6)9\{\alpha\} = (0.6)_9.

Combining both parts gives

(121.2)3=(17.6)9.(121.2)_3 = (17.6)_9.

As a sanity check, both sides are equal to 162316\frac{2}{3} in decimal. Pad the integer part with leading zeros on the left, but pad the fractional part with trailing zeros on the right; padding the wrong side changes the number.

Converting Between Two Composite Bases (bm→bnb^m \to b^n)#

To convert between two bases that share a root but are not direct powers of each other (e.g., base 1616 and base 88, which both share root 22), apply the Expansion algorithm followed by the Grouping algorithm.

Example. Convert ((11)(10).(11)‾)16((11)(10).\overline{(11)})_{16} to base 88.

Here, we convert from base 1616 (242^4) to the intermediate base 22, and then group into base 88 (232^3).

Step 1: Expand base 16 to base 2 (m=4m=4).

(11)16=10112(10)16=10102(11)16=10112\begin{aligned} (11)_{16} &= 1011_2 \\ (10)_{16} &= 1010_2 \\ (11)_{16} &= 1011_2 \end{aligned}

The intermediate representation is (10111010.1011‾)2(10111010.\overline{1011})_2.

Step 2: Group base 2 to base 8 (m=3m=3).
Integer part (start at radix, move left):

101110102  ⟹  010⏟2    111⏟7    010⏟210111010_2 \implies \underbrace{010}_{2} \;\; \underbrace{111}_{7} \;\; \underbrace{010}_{2}

Thus, ⌊α⌋=(272)8\lfloor \alpha \rfloor = (272)_8.

Fractional part (start at radix, move right):
The period k=4k=4 (1011) and the block size m=3m=3. The lowest common multiple of 44 and 33 is 1212, meaning we must write out 1212 bits of the repeating sequence before it perfectly aligns with our blocks of 33.

0.101110111011…20.101110111011\dots_2

Grouping by 3 moving right:

101⏟5    110⏟6    111⏟7    011⏟3\underbrace{101}_{5} \;\; \underbrace{110}_{6} \;\; \underbrace{111}_{7} \;\; \underbrace{011}_{3}

After these 1212 bits, the grouped sequence of base 88 digits will repeat identically.
Thus, {α}=(0.5673‾)8\{\alpha\} = (0.\overline{5673})_8.
Combining both parts gives the final unique representation:

((11)(10).(11)‾)16=(272.5673‾)8((11)(10).\overline{(11)})_{16} = (272.\overline{5673})_8

Divisibility Tricks from Base-bb Digits#

A nice payoff of understanding base representations is that the familiar base 10 divisibility tests (last digit for 22 and 55, digit sums for 33 and 99) all generalise, letting us read divisibility facts straight off the digits without converting anything.

Suppose N=(dndn−1…d1d0)bN = (d_n d_{n-1} \dots d_1 d_0)_b is a positive integer. Notice that for any i∈Z+i \in \mathbb{Z}^+,

bi−1=(b−1)(bi−1+bi−2+⋯+b+1),b^i - 1 = (b-1)(b^{i-1} + b^{i-2} + \cdots + b + 1),

so b−1b-1 divides bi−1b^i - 1 for every positive ii. Subtracting the digit sum from NN,

N−(dn+dn−1+⋯+d0)=∑i=0ndibi−∑i=0ndi=∑i=1ndi(bi−1),\begin{align*} N - (d_n + d_{n-1} + \cdots + d_0) &= \sum_{i=0}^{n} d_i b^i - \sum_{i=0}^{n} d_i \\ &= \sum_{i=1}^{n} d_i(b^i - 1), \end{align*}

which is a sum of multiples of b−1b-1 and is hence itself divisible by b−1b-1 (basically Lemma 1.3 from Topic 1 applied repeatedly). Therefore,

(dndn−1…d0)b and its digit sum dn+dn−1+⋯+d0 differ by a multiple of b−1.\boxed{(d_n d_{n-1} \dots d_0)_b \text{ and its digit sum } d_n + d_{n-1} + \cdots + d_0 \text{ differ by a multiple of } b-1.}

So b−1b-1 divides NN if and only if it divides the digit sum, and the same holds for any divisor of b−1b-1. In base 10 this is the digit sum test for 33 and 99 (i.e. casting out nines); in base 5 it becomes a digit sum test for 22 and 44.

Similarly, every divisor cc of bb divides bib^i for all i≥1i \geq 1, so cc divides all of NN except possibly the last digit; that is, c∣Nc \mid N if and only if c∣d0c \mid d_0. In base 10 this is the last digit test for 22, 55 and 1010; in base 2 it says a binary integer is even exactly when it ends in 00 (e.g. (10111)2=23(10111)_2 = 23 is odd on sight).

Example. Without converting to decimal, decide whether (1313)5(1313)_5 is even, and whether it is divisible by 44. Then verify by converting.
Since the base 55 is odd, the last digit tells us nothing about parity; but 22 and 44 both divide b−1=4b - 1 = 4, so the digit sum test handles both at once. The digit sum is

1+3+1+3=8,1 + 3 + 1 + 3 = 8,

and since 2∣82 \mid 8 and 4∣84 \mid 8, the number is divisible by both 22 and 44. Verifying,

(1313)5=(1×53)+(3×52)+(1×51)+(3×50)=125+75+5+3=208=4×52.\begin{align*} (1313)_5 &= (1 \times 5^3) + (3 \times 5^2) + (1 \times 5^1) + (3 \times 5^0) \\ &= 125 + 75 + 5 + 3 \\ &= 208 \\ &= 4 \times 52. \end{align*}

Therefore, (1313)5(1313)_5 is divisible by 44 (and hence even), exactly as the digit sum promised. In base bb, use the last digit to test divisors of bb and the digit sum to test divisors of b−1b-1; testing parity by the last digit only works when the base is even.

There is also an alternating digit sum test for divisors of b+1b+1 (generalising the base 10 test for 1111), which comes from the fact that b+1b+1 always divides bi−(−1)ib^i - (-1)^i; deriving it is a good exercise.