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
Some numbers have two representations in base 10, i.e.
Here, represents both and .
Note
Definition 2.1
For any integer , the base representation of the number is written as the digit string
for some , where
and for each digit we have that with .
Furthermore, for all , we require that
Basically, base works exactly like the decimal system except that each position now scales by a power of instead of a power of , and the only digits allowed are up to . 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 rather than
The final condition in the definition bans digit strings that end in the digit repeating forever. This is exactly the base version of the situation from above; without this condition, some numbers would have two different representations and the notation would be ambiguous.
Example. Show that in every base .
Let . Multiplying by shifts the radix point one place to the right, so
Therefore, , , , and so on; the trick was never really about 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 we run out of ordinary digits, so any digit larger than is surrounded with brackets, e.g. . In some bases such as base 16 (hexadecimal), it is instead standard to use capital letters as the new digits.
Example. Convert to a decimal (base 10) number.
Here, each digit represents the following;
, therefore,
Example. Convert to a decimal number.
Each digit gets multiplied by the power of determined by its position;
Therefore, .
Example. Convert to a decimal number.
Base 60 needs sixty different digits, so the digits and are written in brackets. The digit string here is , and each digit is multiplied by a power of ;
Therefore, . Do not read as the digit string ; each bracketed block is one single digit.
Example. Convert to a decimal number.
Digits after the radix point are multiplied by negative powers of the base;
Therefore, .
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 representation of a number can be written in the form:
for some natural numbers and .
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, , and .
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 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 be an integer and let with . Then the base representation of terminates if and only if every prime factor of also divides (equivalently, for some ).
Basically, a terminating representation is just a fraction of the form , and can be rewritten in that form precisely when all of 's prime factors already appear in .
Example. Without converting, decide whether each of the following terminates or recurs: in base 6, in base 5, and in base 2.
- For in base 6: , whose only prime factor is , and ; the representation terminates.
- For in base 5: , and ; the representation is periodic.
- For in base 2: , and ; the representation is periodic.
Therefore whether a rational terminates depends on the base; 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 to a decimal (base 10) number.
Suppose , then,
This method for periodic base representations can be generalised as follows:
- Let be the number in base representation and let be the period length.
- Find by shifting the radix point places to the right.
- Calculate to eliminate the repeating part.
- Factorise the left-hand side and divide to get in base .
- Convert the numerator and denominator to decimal forms and simplify the fraction if necessary.
Example. Express as a decimal fraction.
Here, , , so the answer would be
In the numerator, the recurring part cancels out after the radix point to only leave which is , meaning we get
or
Doing this the normal way would be:
Suppose , then,
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 with ,
The idea is to treat each copy of the repeating block as one term of a geometric series, since every copy is times smaller than the copy before it, where is the period length. The derivation of this formula is first year stuff so I'm not writing it out.
Example. Write as a decimal fraction using the geometric series formula.
The repeating block is worth , and the first copy of the block sits in the first three places after the radix point, so it is worth ; every later copy is times smaller than the one before it. Hence,
Therefore, , agreeing with the shifting method from before.
Example. Write as a decimal fraction using the geometric series formula.
Split the number into its non-repeating head and its repeating tail. The head is
and the tail is made of copies of the block , where the first copy ends four places after the radix point (so it is worth ) and each later copy is times smaller;
Adding the two parts together,
which matches the shifting method. In general, use the shifting method when the digit subtraction 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 to a fraction.
The period starts immediately after the radix point, so the shortcut applies directly with and ;
Therefore, . Notice how terminates in base 10 but recurs in base 2, since , exactly as the terminating criterion predicted; this is basically why computers, which store numbers in binary, can never represent exactly.
A Base Conversion Algorithm
Note
Theorem
For any and integer , the base representation of as defined in Definition 2.1 is unique.
The naive way to convert some into base would be to find the largest power that does not exceed , take the largest multiple of 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 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 to some other base , we use two algorithms,
- one for the integer part ; and
- one for the fractional part .
Integer Part: Use the division algorithm to find quotients and remainders when dividing by iteratively.
The remainders from each step form the digits of the integer part of in reverse. That is,
Fractional part: Set and iteratively multiply by , writing the result as a sum of its integer part and its fractional part :
and if is rational then the process will terminate at the th step, when either:
- , so ; or
- for some , in which case the expansion is periodic, and .
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 in base 6.
To convert to base , we split the number into its integer part and its fractional part , and apply the two algorithms.
Integer Part: Use the division algorithm to find quotients and remainders when dividing by iteratively.
The remainders from each step form the digits of the integer part of in reverse. That is,
Fractional part: Set and iteratively multiply by , writing the result as a sum of its integer part and its fractional part :
Because , the process terminates at the rd step. So,
Combining the integer and fractional parts gives the final unique representation:
Notice that and , so the terminating criterion knew this fractional part would terminate before we ran a single step.
Example. Write in base 5.
Since , there is no integer part to worry about; . Also, and , so the terminating criterion warns us in advance that the expansion will be periodic; the algorithm must end with a repeated remainder rather than with .
Fractional part: Set and iteratively multiply by :
Here , so the process terminates at the th step with and ; every digit strictly after repeats indefinitely. Therefore,
Notice how after the first step every remainder is a fraction with denominator ; there are only six possible non-zero values , 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 in base 16.
This is the integer part algorithm again, except now the remainders can be larger than , so we translate them into hexadecimal digits at the end ().
Reading the remainders in reverse gives
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 is the digit , not the two digits and .
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 (e.g., base and base ), we can bypass the standard base 10 conversion algorithms. Instead, we use base as an intermediate system.
Note
Theorem
For any integer and positive integers , every single digit in base corresponds uniquely to a block of exactly digits in base .
This property allows us to translate numbers by "expanding" digits into blocks or "grouping" blocks into single digits.
To convert from a larger base to a smaller base , expand each individual digit of the base number into its -digit representation in base . Padding with leading zeros is required to ensure every intermediate block has exactly digits.
To convert from a smaller base to a larger base , group the base digits into blocks of length .
- 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 with a period length of , and we are grouping into blocks of length to convert to base , the period may not immediately align with the block size.
To find the new periodic representation, the base sequence must be written out until the period length and the block size perfectly synchronize. This synchronization occurs at the least common multiple (LCM) of and .
The new period length in base will be .
Example. Convert to base .
Here, we are moving from base () to base , so and . We expand each base 8 digit into exactly 3 base 2 digits.
Integer part:
Fractional part:
Stringing these blocks together in order yields the base 2 representation. Leading zeros on the integer part can be omitted:
Example. Convert to base .
Here, we are moving from base to base (), so and . We group the digits into blocks of 4. Standard base 16 notation applies ().
Integer part (start at radix, move left):
Therefore, .
Fractional part (start at radix, move right):
The fraction is , meaning the block repeats infinitely: . We group these into blocks of 4 moving right:
Because the block repeats indefinitely, the new period is simply .
Therefore, .
Combining both parts:
(Check: both sides equal ; note we avoid a repeating on its own, since a tail of infinitely repeating digits is forbidden by Definition 2.1.)
Example. Write in base 9.
Here , so and ; we group the base 3 digits into blocks of .
Integer part (start at radix, move left): the string has odd length, so the leftmost block gets padded with a leading zero,
since and . Therefore, .
Fractional part (start at radix, move right): the string is too short for a full block, so it gets padded with a trailing zero (trailing zeros past the radix point change nothing),
since . Therefore, .
Combining both parts gives
As a sanity check, both sides are equal to 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 ()
To convert between two bases that share a root but are not direct powers of each other (e.g., base and base , which both share root ), apply the Expansion algorithm followed by the Grouping algorithm.
Example. Convert to base .
Here, we convert from base () to the intermediate base , and then group into base ().
Step 1: Expand base 16 to base 2 ().
The intermediate representation is .
Step 2: Group base 2 to base 8 ().
Integer part (start at radix, move left):
Thus, .
Fractional part (start at radix, move right):
The period (1011) and the block size . The lowest common multiple of and is , meaning we must write out bits of the repeating sequence before it perfectly aligns with our blocks of .
Grouping by 3 moving right:
After these bits, the grouped sequence of base digits will repeat identically.
Thus, .
Combining both parts gives the final unique representation:
Divisibility Tricks from Base- Digits
A nice payoff of understanding base representations is that the familiar base 10 divisibility tests (last digit for and , digit sums for and ) all generalise, letting us read divisibility facts straight off the digits without converting anything.
Suppose is a positive integer. Notice that for any ,
so divides for every positive . Subtracting the digit sum from ,
which is a sum of multiples of and is hence itself divisible by (basically Lemma 1.3 from Topic 1 applied repeatedly). Therefore,
So divides if and only if it divides the digit sum, and the same holds for any divisor of . In base 10 this is the digit sum test for and (i.e. casting out nines); in base 5 it becomes a digit sum test for and .
Similarly, every divisor of divides for all , so divides all of except possibly the last digit; that is, if and only if . In base 10 this is the last digit test for , and ; in base 2 it says a binary integer is even exactly when it ends in (e.g. is odd on sight).
Example. Without converting to decimal, decide whether is even, and whether it is divisible by . Then verify by converting.
Since the base is odd, the last digit tells us nothing about parity; but and both divide , so the digit sum test handles both at once. The digit sum is
and since and , the number is divisible by both and . Verifying,
Therefore, is divisible by (and hence even), exactly as the digit sum promised. In base , use the last digit to test divisors of and the digit sum to test divisors of ; testing parity by the last digit only works when the base is even.
There is also an alternating digit sum test for divisors of (generalising the base 10 test for ), which comes from the fact that always divides ; deriving it is a good exercise.