See How Things Work

Arithmetic in other bases

Unit
Number Bases
Part
1. Number Bases
Lesson
1.4

The column methods of addition, subtraction and multiplication work in every base exactly as in base ten, once ten is replaced by the base b: a place that reaches b carries one group to the next place, and a borrowed group is worth b. This lesson builds the tables of small bases, proves the column methods in base b, works through binary, octal and hexadecimal examples, and checks every result in base ten.

Tables of a small base

Arithmetic in another base needs no new ideas: the operations are carried out in exactly the same way as in the decimal system.⁠[1] A change of base leaves the rules of the numeral system as they are in base ten.⁠[2] What changes is the table of facts to be known. Small bases such as 2 and 3 have very small addition and multiplication tables, at the price of long numerals;⁠[3] at the other extreme, the multiplication tables of Babylonian arithmetic in base 60 require sixty tables of sixty lines each.⁠[4]

Proposition (the sum of two digits).

Let x and y be digits of base b. If x + y < b, the sum is the single digit x + y. If x + y ≥ b, the sum is written with two digits, 1 and x + y − b: one group of b and x + y − b ones.

Proof.

The first case needs no proof. In the second, x + y = b + (x + y − b), that is 1 × b + (x + y − b). Since x and y are at most b − 1, x + y − b is at most b − 2, so it is a digit, and by lesson 1.1 the numeral with digits 1 and x + y − b names exactly this number.

+01234
001234
1123410
22341011
334101112
4410111213
Table. The addition table of base five. Every entry is written in base five; the shaded sums are five or more, so they need two digits, the first of which is 1: for example 4 + 3 = 12₅, one five and two ones.
Example (The binary addition table).

Write the sums 0 + 0, 0 + 1, 1 + 1 and 1 + 1 + 1 in base two.

  1. 0 + 0 = 0 and 0 + 1 = 1 + 0 = 1: single digits.
  2. 1 + 1 = 2, which is the base: one group of two and no ones, 10₂.
  3. 1 + 1 + 1 = 3 = 1 × 2 + 1, written 11₂.

Answer: 0, 1, 10₂ and 11₂. Binary addition needs no other facts.

Adding in columns

The column addition of Addition lesson 1.8 adds place by place from the right and carries when a place reaches ten. In base b it carries when a place reaches b. Binary addition is done by the usual pencil-and-paper method in exactly this way, adding the bits of each place together with the carries.⁠[5]

Theorem (column addition in base b).

To add two numerals in base b, line them up by place and work from the right. At each place add the two digits and the carry from the place on the right (0 at the first place). If the total t is less than b, write t and carry 0; if t ≥ b, write t − b and carry 1. A last carry 1 becomes a new leftmost digit. The digits written form the numeral of the sum, and every carry is 0 or 1.

Proof.

Write both numbers as expansions. By the commutative and associative properties of addition the terms can be collected place by place, and by the distributive property (Multiplication lesson 1.7) xₖ × bᵏ + yₖ × bᵏ = (xₖ + yₖ) × bᵏ. So the sum is the sum over the places of (digit + digit) × bᵏ.

Work from the right. If the total t at place k, including the carry, is b or more, then t × bᵏ = (t − b) × bᵏ + b × bᵏ, and b × bᵏ = bᵏ⁺¹ is one group of place k + 1 (lesson 1.1): it is moved to the next place as the carry. The carry into the first place is 0. If the carry into a place is 0 or 1, the total there is at most (b − 1) + (b − 1) + 1 = 2b − 1, less than 2b, so t − b is at most b − 1, a digit, and the carry out of the place is again 0 or 1. Step by step from the right, every carry is 0 or 1. When all places are done, each place holds a single digit, so the sum is written as an expansion with digits less than b: by lesson 1.1 it is the numeral of the sum.

The proof is the base-ten proof with b in place of ten. In binary the first place gives one bit of the sum and a carry that is either 0 or 1,⁠[6] and by the Theorem the same holds at every place.

Caution.

The bound on the carries holds for the sum of two numerals. When three or more numerals are added in one column sum, a place can collect 2b or more, and the carry can be 2 or more. For example, 1₂ + 1₂ + 1₂ + 1₂: place 0 holds 4 = 2 × 2 + 0, so it writes 0 and carries 2 = 10₂, and the sum is 100₂ = 4. Such a sum is safest done two numerals at a time.

1
1
1
1
1
0
1
1
+
1
1
1
1
0
0
1
0
  1. Place 0: 1 + 1 = 2, which is 2 or more: 2 of them make one group of the next place. Write 2 − 2 = 0 and carry 1.
  2. Place 1: 1 + 1 + 1 = 3, which is 2 or more: 2 of them make one group of the next place. Write 3 − 2 = 1 and carry 1.
  3. Place 2: 0 + 1 + 1 = 2, which is 2 or more: 2 of them make one group of the next place. Write 2 − 2 = 0 and carry 1.
  4. Place 3: 1 + 0 + 1 = 2, which is 2 or more: 2 of them make one group of the next place. Write 2 − 2 = 0 and carry 1.
  5. Place 4: only the carry, 1. Write 1.
Figure. 1011₂ + 111₂ in columns. Every place reaches 2 and carries 1; the last carry starts a new place. The sum is 10010₂, that is 11 + 7 = 18.
Example (Adding in binary).

Add 1011₂ + 111₂.

  1. Place 0: 1 + 1 = 10₂. Write 0, carry 1.
  2. Place 1: 1 + 1 + 1 = 11₂. Write 1, carry 1.
  3. Place 2: 0 + 1 + 1 = 10₂. Write 0, carry 1.
  4. Place 3: 1 + 0 + 1 = 10₂ (the second numeral has no digit there). Write 0, carry 1.
  5. Place 4: only the carry. Write 1.

Answer: 1011₂ + 111₂ = 10010₂. Check in base ten: 11 + 7 = 18 = 16 + 2 = 10010₂.

Example (Adding in base five).

Add 342₅ + 214₅.

  1. Place 0: 2 + 4 = 6 = 1 × 5 + 1. Write 1, carry 1.
  2. Place 1: 4 + 1 + 1 = 6. Write 1, carry 1.
  3. Place 2: 3 + 2 + 1 = 6. Write 1, carry 1.
  4. Place 3: the carry. Write 1.

Answer: 1111₅. Check: 342₅ = 75 + 20 + 2 = 97 and 214₅ = 50 + 5 + 4 = 59; 97 + 59 = 156; and 1111₅ = 125 + 25 + 5 + 1 = 156.

Example (Adding in hexadecimal).

Add 9A₁₆ + 7C₁₆.

  1. Place 0: A + C = 10 + 12 = 22 = 16 + 6. Write 6, carry 1.
  2. Place 1: 9 + 7 + 1 = 17 = 16 + 1. Write 1, carry 1.
  3. Place 2: the carry. Write 1.

Answer: 116₁₆. Check: 9A₁₆ = 154, 7C₁₆ = 124, 154 + 124 = 278, and 116₁₆ = 256 + 16 + 6 = 278.

Example (A common mistake: carrying at ten).

Someone adds 342₅ + 214₅ and writes 556₅. Find the mistake.

  1. Place 0: 2 + 4 = 6 was written as the digit 6, and place 1 got 4 + 1 = 5. The habit of base ten waits for ten before carrying.
  2. But 6 and 5 are not digits of base five. Every total of 5 or more must carry.

Answer: the sum is 1111₅, as found above. A digit equal to or larger than the base always signals a missed carry.

Game

Columns in base b

Round
1
Score
0
Streak
0

Work out 20235 + 44105 in base 5, column by column from the right. Type one digit under each column.

2
0
2
3
+
4
4
1
0

Subtracting with borrowing

Column subtraction (Subtraction lesson 1.5) borrows when a top digit is smaller than the digit below it: one group of the place on the left is broken up into ten of this place. In base b the group breaks into b, because one group of place k + 1 is b groups of place k: bᵏ⁺¹ = b × bᵏ.

Theorem (column subtraction in base b).

Let x ≥ y be numbers written in base b. Subtract place by place from the right. When the top digit, less any group lent to the right, is smaller than the bottom digit, take one group from the place on the left: it adds b to this place. The digits written, with the zeros on their left dropped, form the numeral of x − y (and if every digit written is 0, then x − y = 0).

Proof.

Borrowing rewrites x without changing it: one group of place k + 1 is replaced by b groups of place k, and 1 × bᵏ⁺¹ = b × bᵏ. At a place that does not borrow, the top count is at least the bottom digit and at most b − 1, so the difference is a digit. At a place that borrows, the top count was less than the bottom digit before b was added, so after adding b the difference is less than b; and it is at least 0, because the top count is at least 0 − 1 and the bottom digit at most b − 1, so the difference is at least −1 + b − (b − 1) = 0. Again it is a digit. Subtracting place by place then gives x − y as an expansion with digits less than b, which by lesson 1.1 is its numeral once zeros on the left are dropped. The leftmost place never needs to borrow: if it did, the digits written would name x − y + bᵐ⁺¹, where m is the leftmost place; but they form a row of m + 1 digits and name at most bᵐ⁺¹ − 1 (lesson 1.1, Exercise 5), so x − y would be less than 0, which is impossible since x ≥ y. This is the argument of Subtraction lesson 1.5 with b in place of ten.

4
7
11
5
0
3
−
1
6
7
3
1
4
  1. Place 0: 3 is less than 7. Take one group from the place on the left: it is worth 8 here, so 3 + 8 = 11, and 11 − 7 = 4.
  2. Place 1: the digit 0 has lent one group to the right, so it first takes one group from the place on the left, worth 8 here: 0 + 8 − 1 = 7, and 7 − 6 = 1.
  3. Place 2: 5, less the 1 lent to the right, is 4; 4 − 1 = 3.
Figure. 503₈ − 167₈ in columns. The small numbers above give the working value of each column after borrowing, in base ten: place 0 borrows and works with 3 + 8 = 11; place 1 holds 0 and has lent one group, so it takes one group from place 2 and works with 8 − 1 = 7; place 2 has lent one group and works with 4. The difference is 314₈.
Example (Borrowing across a zero in base eight).

Subtract 503₈ − 167₈.

  1. Place 0: 3 is less than 7. Place 1 holds 0, so the group comes from place 2: place 2 keeps 4, place 1 becomes 8 − 1 = 7, and place 0 becomes 3 + 8 = 11. 11 − 7 = 4.
  2. Place 1: 7 − 6 = 1.
  3. Place 2: 4 − 1 = 3.

Answer: 314₈. Check by adding back (Subtraction lesson 1.7): 314₈ + 167₈: 4 + 7 = 11 = 13₈, write 3 carry 1; 1 + 6 + 1 = 8 = 10₈, write 0 carry 1; 3 + 1 + 1 = 5. The sum is 503₈. In base ten: 323 − 119 = 204 = 3 × 64 + 1 × 8 + 4.

Example (Borrowing across zeros in binary).

Subtract 1000₂ − 11₂.

  1. Place 0: 0 is less than 1, and places 1 and 2 hold 0: the group comes from place 3. Place 3 becomes 0, places 2 and 1 become 1 (each passes one on), and place 0 becomes 0 + 2 = 2. 2 − 1 = 1.
  2. Place 1: 1 − 1 = 0. Place 2: 1 − 0 = 1. Place 3: 0.

Answer: 1000₂ − 11₂ = 101₂. Check: 8 − 3 = 5 = 101₂. In binary every 0 crossed by a borrow becomes 1, the largest digit, just as it becomes 9 in base ten.

Multiplying

Multiplication by one digit works place by place from the right, as in Multiplication lesson 1.9: multiply the digit of each place, add the carry, write the result minus whole groups of b, and carry the number of groups. Here the carry can be more than 1. For a multiplier with several digits, the distributive property splits the product into one partial product per digit; by lesson 1.2, multiplying by b writes a 0 at the end, so each partial product is shifted one place more than the one before. Binary multiplication follows the conventional pencil-and-paper method in exactly this way,⁠[7] and it is especially simple: the only table facts are 0 × 0 = 0 × 1 = 0 and 1 × 1 = 1, and multiplying by 2 shifts the binary numeral one place to the left and adds a 0 at its end.⁠[8]

×01234
000000
101234
20241113
303111422
404132231
Table. The multiplication table of base five, every entry written in base five. The shaded products are five or more: 4 × 4 = 16 = 31₅, three fives and one.
Example (A one-digit multiplier in base five).

Multiply 23₅ × 4₅.

  1. Place 0: 3 × 4 = 12 = 2 × 5 + 2. Write 2, carry 2.
  2. Place 1: 2 × 4 + 2 = 10 = 2 × 5 + 0. Write 0, carry 2.
  3. Place 2: the carry. Write 2.

Answer: 23₅ × 4₅ = 202₅. Check: 13 × 4 = 52 = 2 × 25 + 0 × 5 + 2. The carries were 2. With a one-digit multiplier a carry can be as large as b − 2, but never larger (Exercise 6).

1101
13
×101
5
1101
bit 1 in place 0: 1101
00000
bit 0 in place 1: 0
+110100
bit 1 in place 2: 1101 with two 0s
1000001
= 65 = 13 × 5
Figure. 1101₂ × 101₂. The multiplier has 1s in places 0 and 2, so the product is 1101₂ plus 1101₂ with two 0s written at the end (multiplied by 2²); the 0 in place 1 contributes nothing. The sum is 1000001₂ = 65 = 13 × 5.
Example (Multiplying in binary).

Multiply 1101₂ × 101₂.

  1. 101₂ = 100₂ + 1₂, so by the distributive property 1101₂ × 101₂ = 1101₂ × 100₂ + 1101₂ × 1₂.
  2. 1101₂ × 100₂: writing two 0s at the end multiplies by 2 twice: 110100₂. And 1101₂ × 1₂ = 1101₂.
  3. Add in columns: 110100₂ + 1101₂. Places 0 to 3: 0 + 1 = 1, 0 + 0 = 0, 1 + 1 = 10₂ (write 0, carry 1), 0 + 1 + 1 = 10₂ (write 0, carry 1). Place 4: 1 + 1 = 10₂ (write 0, carry 1). Place 5: 1 + 1 = 10₂ (write 0, carry 1). Place 6: 1.

Answer: 1000001₂. Check: 13 × 5 = 65 = 64 + 1 = 1000001₂.

Example (The edge case: multiplying by the base).

Multiply 213₄ × 10₄ and 7E₁₆ × 10₁₆.

  1. 10₄ is 4, the base, and 10₁₆ is 16, the base. By lesson 1.2, multiplying by the base writes a 0 at the end.
  2. So 213₄ × 10₄ = 2130₄ and 7E₁₆ × 10₁₆ = 7E0₁₆.

Answer: 2130₄ and 7E0₁₆. Check the first: 213₄ = 32 + 4 + 3 = 39, and 2130₄ = 128 + 16 + 12 = 156 = 39 × 4.

Caution.

Every computation in another base can be checked by converting the numbers to base ten (lesson 1.3), doing the computation there, and converting back. The check uses only what the earlier lessons proved: a numeral names one number, whatever the base, and the operations act on numbers, not on numerals.

Exercises

Exercise .

Add 1101₂ + 1011₂ in columns, and check in base ten.

▸ Show solution

Place 0: 1 + 1 = 10₂, write 0 carry 1. Place 1: 0 + 1 + 1 = 10₂, write 0 carry 1. Place 2: 1 + 0 + 1 = 10₂, write 0 carry 1. Place 3: 1 + 1 + 1 = 11₂, write 1 carry 1. Place 4: 1. So 1101₂ + 1011₂ = 11000₂. Check: 13 + 11 = 24 = 16 + 8.

Exercise .

Add (a) 2213₄ + 1322₄; (b) 7A₁₆ + 2F₁₆.

▸ Show solution

(a) Place 0: 3 + 2 = 5 = 1 × 4 + 1, write 1 carry 1. Place 1: 1 + 2 + 1 = 4, write 0 carry 1. Place 2: 2 + 3 + 1 = 6 = 4 + 2, write 2 carry 1. Place 3: 2 + 1 + 1 = 4, write 0 carry 1. Place 4: 1. So 2213₄ + 1322₄ = 10201₄. Check: 167 + 122 = 289 = 256 + 2 × 16 + 1.

(b) A + F = 10 + 15 = 25 = 16 + 9, write 9 carry 1; 7 + 2 + 1 = 10 = A. So 7A₁₆ + 2F₁₆ = A9₁₆. Check: 122 + 47 = 169 = 10 × 16 + 9.

Exercise .

Subtract (a) 10010₂ − 111₂; (b) 400₅ − 123₅.

▸ Show solution

(a) 10010₂ − 111₂. Place 0: 0 < 1; the group comes from place 1, which holds 1: place 1 becomes 0 and place 0 becomes 2; 2 − 1 = 1. Place 1: 0 < 1; places 2 and 3 hold 0, so the group comes from place 4: place 4 becomes 0, places 3 and 2 become 1, place 1 becomes 2; 2 − 1 = 1. Place 2: 1 − 1 = 0. Place 3: 1 − 0 = 1. So the difference is 1011₂. Check: 18 − 7 = 11 = 8 + 2 + 1.

(b) 400₅ − 123₅. Place 0 borrows across the 0 of place 1: place 2 keeps 3, place 1 becomes 4, place 0 becomes 5; 5 − 3 = 2; 4 − 2 = 2; 3 − 1 = 2. So 222₅. Check: 100 − 38 = 62 = 50 + 10 + 2.

Exercise .

Multiply (a) 34₅ × 3₅; (b) 1011₂ × 110₂.

▸ Show solution

(a) 4 × 3 = 12 = 2 × 5 + 2: write 2, carry 2. 3 × 3 + 2 = 11 = 2 × 5 + 1: write 1, carry 2. Write 2. So 34₅ × 3₅ = 212₅. Check: 19 × 3 = 57 = 50 + 5 + 2.

(b) 110₂ = 100₂ + 10₂, so 1011₂ × 110₂ = 101100₂ + 10110₂ = 1000010₂. Check: 11 × 6 = 66 = 64 + 2.

Exercise .

In which base b is 23 + 14 = 41 true, all three numerals written in base b?

▸ Show solution

23 in base b names 2b + 3, 14 names b + 4 and 41 names 4b + 1. The equation says 3b + 7 = 4b + 1, so b = 6. The digits 2, 3, 1 and 4 are all less than 6, so the numerals are valid. Check in base six: 3 + 4 = 7 = 11₆, write 1 carry 1; 2 + 1 + 1 = 4. The sum is 41₆.

Exercise .

Prove that when a numeral in base b is multiplied by a single digit, every carry is at most b − 2. What does this say in base two?

▸ Show solution

Multiplying by one digit d, each place gives (digit × d) + carry. If the carry into a place is at most b − 2, the total is at most (b − 1) × (b − 1) + (b − 2) = b × b − b − 1, which is less than (b − 1) × b. So the number of whole groups of b in it, the next carry, is at most b − 2. The first carry in is 0, so every carry is at most b − 2. In base two this means the carries are 0: the product of a numeral by a single bit is the numeral itself or 0.

Summary

  1. Arithmetic in base b uses the same column methods as in base ten, with b in place of ten. Only the tables of facts change: tiny in base two, huge in base sixty.
  2. Addition: add each place with the carry; a total of b or more writes total − b and carries 1. With two addends every carry is 0 or 1.
  3. Subtraction: a borrowed group of the next place is worth b, not ten; a 0 crossed by a borrow becomes b − 1.
  4. Multiplication: multiply place by place with carries (up to b − 2 for a one-digit multiplier), and shift partial products, since multiplying by b writes a 0. In binary, multiplying is shifting and adding.
  5. Any result can be checked by converting to base ten.

Sources

  1. 1.
    Georges Ifrah, The Universal History of Numbers: From Prehistory to the Invention of the Computer (trans. David Bellos, E. F. Harding, Sophie Wood and Ian Monk, John Wiley & Sons, 2000).
    Chapter 2, “Base Numbers and the Birth of Number-Systems”, section “Advantages and Drawbacks of Base 10”, p. 41 (the whole topic: pp. 40–41).
    “As for arithmetical operations, they could be carried out just as well in these other bases, and in exactly the same way as we do in our present decimal system.”
    Used for: arithmetic in another base is done in exactly the same way as in the decimal system.
  2. 2.
    Georges Ifrah, The Universal History of Numbers: From Prehistory to the Invention of the Computer (trans. David Bellos, E. F. Harding, Sophie Wood and Ian Monk, John Wiley & Sons, 2000).
    Chapter 27, “Beyond Perfection”, p. 592 (the whole topic: pp. 592).
    “and its fundamental rules would be identical to those which we know already for our decimal system.”
    Used for: a change of base leaves the rules of the numeral system as they are in the decimal system.
  3. 3.
    Georges Ifrah, The Universal History of Numbers: From Prehistory to the Invention of the Computer (trans. David Bellos, E. F. Harding, Sophie Wood and Ian Monk, John Wiley & Sons, 2000).
    Chapter 2, “Base Numbers and the Birth of Number-Systems”, section “Advantages and Drawbacks of Base 10”, p. 40 (the whole topic: pp. 40–41).
    “small bases such as 2 and 3 produce very small multiplication and addition tables to learn by heart; but they require very lengthy strings to express even relatively small numbers”
    Used for: small bases have very small addition and multiplication tables but long numerals.
  4. 4.
    Georges Ifrah, The Universal History of Numbers: From Prehistory to the Invention of the Computer (trans. David Bellos, E. F. Harding, Sophie Wood and Ian Monk, John Wiley & Sons, 2000).
    Chapter 2, “Base Numbers and the Birth of Number-Systems”, section “Advantages and Drawbacks of Base 10”, p. 40 (the whole topic: pp. 40–41).
    “the multiplication tables for even very simple Babylonian arithmetic require considerable feats of memorisation (sixty tables, each with sixty lines.)”
    Used for: base 60 needs sixty multiplication tables of sixty lines each.
  5. 5.
    Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).
    Chapter 4, “Number Theory and Cryptography”, section 4.2, “Integer Representations and Algorithms” (4.2.3, “Algorithms for Integer Operations”: “Addition Algorithm”), p. 264 (the whole topic: pp. 264–265).
    “A procedure to perform addition can be based on the usual method for adding numbers with pencil and paper. This method proceeds by adding pairs of binary digits together with carries, when they occur, to compute the sum of two integers.”
    Used for: binary addition follows the usual pencil-and-paper method, adding the bits of each place with the carries.
  6. 6.
    Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).
    Chapter 4, “Number Theory and Cryptography”, section 4.2, “Integer Representations and Algorithms” (4.2.3, “Algorithms for Integer Operations”: “Addition Algorithm”), p. 264 (the whole topic: pp. 264–265).
    “where s₀ is the rightmost bit in the binary expansion of a + b and c₀ is the carry, which is either 0 or 1.”
    Used for: in binary column addition each place writes one bit and carries the other, and the carry is 0 or 1.
  7. 7.
    Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).
    Chapter 4, “Number Theory and Cryptography”, section 4.2, “Integer Representations and Algorithms” (4.2.3, “Algorithms for Integer Operations”: “Multiplication Algorithm”), p. 265 (the whole topic: pp. 265–266).
    “The conventional algorithm (used when multiplying with pencil and paper) works as follows.”
    Used for: binary multiplication follows the conventional pencil-and-paper method (with the distributive law, as the text goes on).
  8. 8.
    Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).
    Chapter 4, “Number Theory and Cryptography”, section 4.2, “Integer Representations and Algorithms” (4.2.3, “Algorithms for Integer Operations”: “Multiplication Algorithm”), p. 265 (the whole topic: pp. 265–266).
    “Each time we multiply a term by 2, we shift its binary expansion one place to the left and add a zero at the tail end of the expansion.”
    Used for: multiplying by 2 shifts the binary numeral one place to the left and adds a 0 at its end.