and for each digit di we have that di∈{0,1,2,…,b−1} with dn>0.
Furthermore, for all k∈Z+, we require that
(d−k,d−k−1,d−k−2,…)b=(b−1,b−1,b−1,…)b.
Basically, base b works exactly like the decimal system except that each position now scales by a power of b instead of a power of 10, and the only digits allowed are 0 up to b−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 10 rather than 10.000…
The final condition in the definition bans digit strings that end in the digit b−1 repeating forever. This is exactly the base b version of the 0.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 in every base b≥2.
Let x=(0.(b−1))b. Multiplying by b shifts the radix point one place to the right, so
Therefore, (0.7)8=1, (0.4)5=1, (0.1)2=1, and so on; the 0.9 trick was never really about 10 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 10 we run out of ordinary digits, so any digit larger than 9 is surrounded with brackets, e.g. (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 to a decimal (base 10) number.
Here, each digit represents the following; A=10,B=11,C=12,D=13⋯F=15, therefore,
Example. Convert (9(15)(33))60 to a decimal number.
Base 60 needs sixty different digits, so the digits 15 and 33 are written in brackets. The digit string here is 9,15,33, and each digit is multiplied by a power of 60;
Definition 2.2
A terminating base representation is one that ends in infinitely many trailing zeros. A terminating base b representation of a number can be written in the form:
(dndn−1⋯d1d0.d−1d−2d−3…d−k)b,
for some natural numbers n and k.
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, and (0.1234)6=(0.12343434…)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 α is rational if and only if its expansion in any base is either terminating or periodic. Equivalently, a real number α 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 and π 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≥2 be an integer and let α=qp∈Q+ with gcd(p,q)=1. Then the base b representation of α terminates if and only if every prime factor of q also divides b (equivalently, q∣bn for some n∈N).
Basically, a terminating representation is just a fraction of the form bnm, and qp can be rewritten in that form precisely when all of q's prime factors already appear in b.
Example. Without converting, decide whether each of the following terminates or recurs: 83 in base 6, 3524 in base 5, and 51 in base 2.
For 83 in base 6: q=8=23, whose only prime factor is 2, and 2∣6; the representation terminates.
For 3524 in base 5: q=35=5×7, and 7∤5; the representation is periodic.
For 51 in base 2: q=5, and 5∤2; the representation is periodic.
Therefore whether a rational terminates depends on the base; 51=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 to a decimal (base 10) number.
Suppose x=(0.123)4, then,
(4)x(42)x(43)x(43−1)x(43−1)xxxx=(1.231)4, (as multiplying a decimal by its own base shifts it 1 to the left),=(12.312)4=(123.123)4=(123.123)4−x=(123)4=(43−1)10(123)4=6327=73.
This method for periodic base representations can be generalised as follows:
Let x be the number in base b representation and let k be the period length.
Find bkx by shifting the radix point k places to the right.
Calculate bkx−x to eliminate the repeating part.
Factorise the left-hand side and divide to get x=bk−1bkx−x in base b.
Convert the numerator and denominator to decimal forms and simplify the fraction if necessary.
Example. Express y=(0.1234)6 as a decimal fraction.
Here, b=6, k=2, so the answer would be
(62−1)10(12.3434)6−(0.1234)6
In the numerator, the recurring part cancels out after the radix point to only leave 34−12 which is 22, meaning we get
(62−1)10(12.22)6
or
y=63015110.
Doing this the normal way would be:
Suppose x=(0.1234)6, then,
Alternatively, we can convert a periodic representation to a decimal fraction using the formula for an infinite geometric series. Recall that for any real r with 0≤∣r∣<1,
k=1∑∞rk=1−rr.
The idea is to treat each copy of the repeating block as one term of a geometric series, since every copy is bk times smaller than the copy before it, where k 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 as a decimal fraction using the geometric series formula.
The repeating block is worth (123)4=1×42+2×4+3=27, and the first copy of the block sits in the first three places after the radix point, so it is worth 4327; every later copy is 43=64 times smaller than the one before it. Hence,
Therefore, (0.123)4=73, agreeing with the shifting method from before.
Example. Write (0.1234)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=61+362=368=92,
and the tail is made of copies of the block (34)6=3×6+4=22, where the first copy ends four places after the radix point (so it is worth 6422) and each later copy is 62=36 times smaller;
which matches the shifting method. In general, use the shifting method when the digit subtraction bkx−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 to a fraction.
The period starts immediately after the radix point, so the shortcut x=bk−1bkx−x applies directly with b=2 and k=4;
x=(24−1)10(0011)2=153=51.
Therefore, (0.0011)2=51. Notice how 51 terminates in base 10 but recurs in base 2, since 5∤2, exactly as the terminating criterion predicted; this is basically why computers, which store numbers in binary, can never represent 0.2 exactly.
Theorem
For any α∈R and integer b≥2, the base b representation of α as defined in Definition 2.1 is unique.
The naive way to convert some α∈R+ into base b would be to find the largest power bk that does not exceed α, take the largest multiple of bk 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 b 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+ to some other base b, we use two algorithms,
one for the integer part ⌊α⌋; and
one for the fractional part {α}.
Integer Part: Use the division algorithm to find quotients qi and remainders di when dividing by b iteratively.
The remainders from each step form the digits of the integer part of α in reverse. That is,
⌊α⌋=(dndn−1…d2d1d0)b.
Fractional part: Set r0={α}=α−⌊α⌋ and iteratively multiply ri−1 by b, writing the result as a sum of its integer part d−i and its fractional part ri:
b×r0b×r1b×rn−1=d−1+r1=d−2+r2⋮=d−n+rnwhere d−1=⌊b×r0⌋ and r1={b×r0},where d−2=⌊b×r1⌋ and r2={b×r1},⋮where d−n=⌊b×rn−1⌋ and rn={b×rn−1},
and if α is rational then the process will terminate at the nth step, when either:
rn=0, so {α}=(0.d−1d−2…d−n)b; or
rn=rk for some k<n, in which case the expansion is periodic, and {α}=(0.d−1d−2…d−kd−(k+1)…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 357983 in base 6.
To convert α=357983 to base b=6, we split the number into its integer part ⌊α⌋=3579 and its fractional part {α}=83, and apply the two algorithms.
Integer Part: Use the division algorithm to find quotients qi and remainders di when dividing by 6 iteratively.
The remainders from each step form the digits of the integer part of α in reverse. That is,
⌊α⌋=(24323)6.
Fractional part: Set r0={α}=83 and iteratively multiply ri−1 by 6, writing the result as a sum of its integer part d−i and its fractional part ri:
6×83=496×41=236×21=3=2+41=1+21=3+0where d−1=2 and r1=41,where d−2=1 and r2=21,where d−3=3 and r3=0
Because r3=0, the process terminates at the 3rd step. So,
{α}=(0.213)6
Combining the integer and fractional parts gives the final unique representation:
357983=(24323.213)6
Notice that 8=23 and 2∣6, so the terminating criterion knew this fractional part would terminate before we ran a single step.
Example. Write 3524 in base 5.
Since 0<3524<1, there is no integer part to worry about; ⌊α⌋=0. Also, 35=5×7 and 7∤5, so the terminating criterion warns us in advance that the expansion will be periodic; the algorithm must end with a repeated remainder rn=rk rather than with rn=0.
Fractional part: Set r0={α}=3524 and iteratively multiply ri−1 by 5:
5×3524=7245×73=7155×71=755×75=7255×74=7205×76=7305×72=710=3+73=2+71=0+75=3+74=2+76=4+72=1+73where d−1=3 and r1=73,where d−2=2 and r2=71,where d−3=0 and r3=75,where d−4=3 and r4=74,where d−5=2 and r5=76,where d−6=4 and r6=72,where d−7=1 and r7=73.
Here r7=73=r1, so the process terminates at the 7th step with n=7 and k=1; every digit strictly after d−1 repeats indefinitely. Therefore,
3524=(0.3203241)5.
Notice how after the first step every remainder is a fraction with denominator 7; there are only six possible non-zero values 71,72,…,76, 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 3499 in base 16.
This is the integer part algorithm again, except now the remainders can be larger than 9, so we translate them into hexadecimal digits at the end (A=10,B=11,…,F=15).
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 13 is the digit D, not the two digits 1 and 3.
When converting a number between two bases that share a common root, meaning both bases are powers of the same integer b (e.g., base bm and base bn), we can bypass the standard base 10 conversion algorithms. Instead, we use base b as an intermediate system.
Note
Theorem
For any integer b≥2 and positive integers m,n, every single digit in base bm corresponds uniquely to a block of exactly m digits in base b.
This property allows us to translate numbers by "expanding" digits into blocks or "grouping" blocks into single digits.
To convert from a larger base bm to a smaller base b, expand each individual digit of the base bm number into its m-digit representation in base b. Padding with leading zeros is required to ensure every intermediate block has exactly m digits.
To convert from a smaller base b to a larger base bm, group the base b digits into blocks of length m.
For the integer part ⌊α⌋, 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 {α}, start at the radix point and group moving strictly to the right.
If a fractional part {α} is periodic in base b with a period length of k, and we are grouping into blocks of length m to convert to base bm, the period may not immediately align with the block size.
To find the new periodic representation, the base b sequence must be written out until the period length k and the block size m perfectly synchronize. This synchronization occurs at the least common multiple (LCM) of k and m.
The new period length in base bm will be mlcm(k,m).
Example. Convert (34.52)8 to base 2.
Here, we are moving from base 8 (23) to base 2, so b=2 and m=3. We expand each base 8 digit into exactly 3 base 2 digits.
Integer part:
3848=0112=1002
Fractional part:
5828=1012=0102
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
Example. Convert (10111.0110)2 to base 16.
Here, we are moving from base 2 to base 16 (24), so b=2 and m=4. We group the digits into blocks of 4. Standard base 16 notation applies (A=10,B=11,…,F=15).
Integer part (start at radix, move left):
101112⟹1000170111
Therefore, ⌊α⌋=(17)16.
Fractional part (start at radix, move right):
The fraction is 0.01102, meaning the block 10 repeats infinitely: 0.01101010…2. We group these into blocks of 4 moving right:
6011010(A)101010(A)1010…
Because the block 1010 repeats indefinitely, the new period is simply A.
Therefore, {α}=(0.6A)16.
Combining both parts:
(10111.0110)2=(17.6A)16
(Check: both sides equal 23125; note we avoid a repeating 1 on its own, since a tail of infinitely repeating b−1 digits is forbidden by Definition 2.1.)
Example. Write (121.2)3 in base 9.
Here 9=32, so b=3 and m=2; we group the base 3 digits into blocks of 2.
Integer part (start at radix, move left): the string 121 has odd length, so the leftmost block gets padded with a leading zero,
1213⟹101721
since (01)3=1 and (21)3=2×3+1=7. Therefore, ⌊α⌋=(17)9.
Fractional part (start at radix, move right): the string 2 is too short for a full block, so it gets padded with a trailing zero (trailing zeros past the radix point change nothing),
23⟹620
since (20)3=2×3+0=6. Therefore, {α}=(0.6)9.
Combining both parts gives
(121.2)3=(17.6)9.
As a sanity check, both sides are equal to 1632 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.
To convert between two bases that share a root but are not direct powers of each other (e.g., base 16 and base 8, which both share root 2), apply the Expansion algorithm followed by the Grouping algorithm.
Example. Convert ((11)(10).(11))16 to base 8.
Here, we convert from base 16 (24) to the intermediate base 2, and then group into base 8 (23).
Step 1: Expand base 16 to base 2 (m=4).
(11)16(10)16(11)16=10112=10102=10112
The intermediate representation is (10111010.1011)2.
Step 2: Group base 2 to base 8 (m=3).
Integer part (start at radix, move left):
101110102⟹201071112010
Thus, ⌊α⌋=(272)8.
Fractional part (start at radix, move right):
The period k=4 (1011) and the block size m=3. The lowest common multiple of 4 and 3 is 12, meaning we must write out 12 bits of the repeating sequence before it perfectly aligns with our blocks of 3.
0.101110111011…2
Grouping by 3 moving right:
5101611071113011
After these 12 bits, the grouped sequence of base 8 digits will repeat identically.
Thus, {α}=(0.5673)8.
Combining both parts gives the final unique representation:
A nice payoff of understanding base representations is that the familiar base 10 divisibility tests (last digit for 2 and 5, digit sums for 3 and 9) all generalise, letting us read divisibility facts straight off the digits without converting anything.
Suppose N=(dndn−1…d1d0)b is a positive integer. Notice that for any i∈Z+,
bi−1=(b−1)(bi−1+bi−2+⋯+b+1),
so b−1 divides bi−1 for every positive i. Subtracting the digit sum from N,
which is a sum of multiples of b−1 and is hence itself divisible by b−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.
So b−1 divides N if and only if it divides the digit sum, and the same holds for any divisor of b−1. In base 10 this is the digit sum test for 3 and 9 (i.e. casting out nines); in base 5 it becomes a digit sum test for 2 and 4.
Similarly, every divisor c of b divides bi for all i≥1, so c divides all of N except possibly the last digit; that is, c∣N if and only if c∣d0. In base 10 this is the last digit test for 2, 5 and 10; in base 2 it says a binary integer is even exactly when it ends in 0 (e.g. (10111)2=23 is odd on sight).
Example. Without converting to decimal, decide whether (1313)5 is even, and whether it is divisible by 4. Then verify by converting.
Since the base 5 is odd, the last digit tells us nothing about parity; but 2 and 4 both divide b−1=4, so the digit sum test handles both at once. The digit sum is
1+3+1+3=8,
and since 2∣8 and 4∣8, the number is divisible by both 2 and 4. Verifying,
Therefore, (1313)5 is divisible by 4 (and hence even), exactly as the digit sum promised. In base b, use the last digit to test divisors of b and the digit sum to test divisors of b−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+1 (generalising the base 10 test for 11), which comes from the fact that b+1 always divides bi−(−1)i; deriving it is a good exercise.