Emzini weCodeUmhlahlandlelaMathematics 2.8 · Whole Numbers and Integers NoticesAll books

Chapter 2/2.8Accelerateabout 10 min

Number bases and binary

Try this first

Suppose humans had only five fingers in total, and counted in groups of five instead of ten. Count 13 stones by putting them into piles of five. How many full piles are there, and how many stones are left over? How might you write that as a two digit number?

Thirteen stones make 2 piles of five and 3 left over. In a base five system we would write this as 23, meaning 2 fives and 3 ones. To avoid confusing it with our twenty three, we write the base as a small number below: 235.

Definition

base The base of a number system is the number of units in one place that are exchanged for one unit in the next place to the left. In base 10 the places are worth 1, 10, 100, 1,000, .... In base 5 they are worth 1, 5, 25, 125, .... For example, in base 5 the digits 23 mean 2 × 5 + 3 = 13.

In base 5 the only digits needed are 0, 1, 2, 3 and 4, since five of anything is exchanged for one of the next place. In base 10 we need ten digits, 0 to 9.

Changing from base 5 to base 10. Multiply each digit by its place value and add.

Worked example 2.7

Convert 14325 to base 10.

The places, from the right, are worth 1, 5, 25 and 125.
1 × 125 + 4 × 25 + 3 × 5 + 2 × 1 = 125 + 100 + 15 + 2 = 242
So 14325 = 242.

Now try one yourself

Changing from base 10 to base 5. Divide by 5 again and again, writing down the remainders. Read the remainders from the last to the first.

Worked example 2.8

Write 242 in base 5.

242 ÷ 5 = 48 remainder 2
48 ÷ 5 = 9 remainder 3
9 ÷ 5 = 1 remainder 4
1 ÷ 5 = 0 remainder 1
Read the remainders upwards: 242 = 14325, which agrees with Worked example 2.7.

Now try one yourself

Why it works. The first division splits 242 stones into 48 piles of 5 with 2 left over: the 2 is the ones digit. Then the 48 piles are grouped in fives: 9 groups of 25 with 3 piles of 5 left over: the 3 is the fives digit. And so on up the places. Each remainder is what cannot be exchanged into the next place.

Binary. The smallest base that works is base 2, called binary. Its places are worth 1, 2, 4, 8, 16, 32, 64, ..., each double the one before, and the only digits are 0 and 1.

Definition

binary Binary is the base 2 number system. It uses only the digits 0 and 1, and its places are worth 1, 2, 4, 8, 16 and so on. For example, the binary number 1101 means 8 + 4 + 1 = 13.

Worked example 2.9
  1. (a)Convert 1011012 to base 10.
  2. (b)Write 50 in binary.
(a)
The places with a 1 are worth 32, 8, 4 and 1.
So 1011012 = 32 + 8 + 4 + 1 = 45.
(b)
Divide by 2 repeatedly, writing r for remainder: 50 ÷ 2 = 25 r 0, 25 ÷ 2 = 12 r 1, 12 ÷ 2 = 6 r 0, 6 ÷ 2 = 3 r 0, 3 ÷ 2 = 1 r 1, 1 ÷ 2 = 0 r 1.
Reading the remainders upwards gives 1100102.
Check: 32 + 16 + 2 = 50.

Now try one yourself

Why computers use binary. A computer chip contains billions of tiny electronic switches. Each switch is either off or on, which can stand for 0 or 1. It is much easier to build a switch that reliably tells "off" from "on" than one that reliably tells apart ten different levels. So everything a computer stores is binary: numbers, letters, photos and music. In a common code, the capital letter A is stored as 65, which is 10000012. When you write programs at Emzini weCode, every line you type is turned into long strings of 0s and 1s before the machine can follow it. The German mathematician Gottfried Wilhelm Leibniz described binary arithmetic in detail around 1700, more than two hundred years before the first electronic computers.

Solving Gogo MaNcube's problem. Now return to the market scale. Suppose Gogo MaNcube buys weights of 1, 2, 4, 8, 16 and 32 kg. To weigh 45 kg she writes 45 in binary: 1011012. The 1s tell her which weights to use: 32 + 8 + 4 + 1 = 45. Every whole number from 1 to 63 can be written in binary with at most six digits (63 = 1111112 = 32 + 16 + 8 + 4 + 2 + 1), so every target can be weighed. Six weights are enough.

45 in binary is 1011011 means the place is used and 0 means it is not: 45 = 32 + 8 + 4 + 1.1THE PLACES OF BINARYplace32168421digit101101used?usednot usedusedusednot usedused1011012 = 32 + 8 + 4 + 1 = 452ON GOGO MANCUBE'S SCALEthe sack is not to scaleMAIZE32 kg8 kg4 kg1 kgmaize meal45 kg32 + 8 + 4 + 1= 45 kg
Figure 2.6 Each binary digit says whether a place is used. The same digits tell Gogo MaNcube which weights to put on the scale.

Could fewer weights work? With five weights, each weight is either in the pan or not, which gives 2 × 2 × 2 × 2 × 2 = 32 choices. One of those choices is "no weights at all", which weighs nothing. That leaves at most 31 different amounts, but she needs 63. So five weights can never be enough, whatever their sizes. Six weights is the smallest number, and 1, 2, 4, 8, 16, 32 kg works. (In fact these are the only six weights that work, but that takes more proof.)

Going further

Weights in both pans. If Gogo MaNcube is allowed to put weights in the same pan as the maize meal, she can do even better. With weights of 1, 3, 9 and 27 kg she can weigh every whole number from 1 kg to 40 kg. For example, to weigh 5 kg she puts 9 kg in one pan and 3 kg and 1 kg with the maize meal: 9 − 3 − 1 = 5. Each weight now has three choices (left pan, right pan, or unused), and this leads to a system called balanced base 3.

Common mistake

Reading a binary number as a base ten number. The binary number 1000 is not one thousand. It is 8.

Check your understanding 2.8

  1. Convert to base 10:
    1. (a)345
    2. (b)20135
    3. (c)110112
    4. (d)10000002
    Show answerHide answer
    1. (a)3 × 5 + 4 = 19
    2. (b)2 × 125 + 0 + 5 + 3 = 258
    3. (c)16 + 8 + 2 + 1 = 27
    4. (d)64
  2. Write in base 5:
    1. (a)19
    2. (b)130
    Show answerHide answer
    1. (a)345
    2. (b)130 = 1 × 125 + 0 × 25 + 1 × 5 + 0, so 10105
  3. Write in binary:
    1. (a)13
    2. (b)37
    3. (c)100
    Show answerHide answer
    1. (a)11012
    2. (b)1001012
    3. (c)11001002
  4. Which weights from 1, 2, 4, 8, 16 and 32 kg does Gogo MaNcube use for 27 kg? For 60 kg?
    Show answerHide answer
    27 = 110112: 16, 8, 2 and 1 kg. 60 = 1111002: 32, 16, 8 and 4 kg.