← Data representation

Bits and binary numbers

A computer stores numbers with switches that are only off (0) or on (1). Put bits side by side, make each place worth double the one on its right (1, 2, 4, 8, 16), and add the places that hold a 1: 10110 = 16 + 4 + 2 = 22.

A computer has no digits from 2 to 9, only switches that are off or on. So how does it store the number 22?

Text, pictures and sound are all stored as numbers. But inside, a computer has no digits from 2 to 9. A bit is one switch that is either off or on. We write off as 0 and on as 1. One bit can only count to 1, so a computer puts bits side by side.

The cards below are bits. Each card is worth double the card on its right, and a card face up is a 1. The number is the total of the cards that are face up. This way of writing numbers is called binary.

PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

Read the cards

Four cards are worth 8, 4, 2 and 1. The 8, 2 and 1 cards are face up, so the bits read **1011**. What number is that?

TryTry it on the board and compare the result with your prediction.

Try: turn up the cards

Was your prediction right? Each 1 adds its card's value; each 0 adds nothing.

Try it yourselfYour edits are saved in this browser.

Click the 8, 2 and 1 cards to turn them face up, so the bits read 1011. What number does the board show?

Use the board. This ticks when you get there.

InvestigateWork out why it happens, one step at a time.

Worked example: read and write binary

Here is 10110 read one place at a time. The places start at 1 on the right and double each time.

Worked exampleBefore each step, say what you think comes next.
  1. 1 0 1 1 01\,0\,1\,1\,0Five bits, so five places.

Now read 10011 the same way.

Which end is the 1 place?

Five cards are worth 16, 8, 4, 2 and 1. What number is **10011** in binary?

Sam reads 1100 in binary. Click the line where the working first goes wrong.

Why do computers store numbers in binary, not with the digits 0 to 9?

ModifyChange the problem on purpose and see what happens.

Vary: one change at a time

Start with the biggest card that fits, then fill in the rest.

Try it yourselfYour edits are saved in this browser.

Make 6. Which cards do you need?

Use the board. This ticks when you get there.

Now make 7, one more. How many cards did you have to change?

Use the board. This ticks when you get there.

Now make 8, one more again. Which cards changed this time?

Use the board. This ticks when you get there.

Make 19 using the 16 card.

Use the board. This ticks when you get there.

Write 13 in binary with four bits (places 8, 4, 2, 1).

PractiseA few on your own, to check you have it.

Read and write binary

What number is **1001** in binary?

What number is **11000** in binary?

Write 20 in binary with five bits.

What number is **11111** in binary?

Review: what is 242^4?

MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

Three cards up

Stretch: what is the smallest number with exactly three cards up? Write it in binary.

Try it yourselfYour edits are saved in this browser.
Need a hint?

The cards on the left are worth the most.

Another hint

Use the three biggest cards.

The number is hidden. Turn up exactly three cards to make the biggest number you can, then work it out.

Use the board. This ticks when you get there.

For teachers

Students turn binary cards face up to see that each place is worth double the one on its right, read and write numbers in binary, and say why computers use two states (AC9TDI8K04). About 40 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

Do the Try board yourself first. If you have time, do CS Unplugged's binary cards activity with real cards before the board: five students hold the 16, 8, 4, 2 and 1 cards at the front and turn them over to make numbers. The board is the same model.

The one idea: each place is worth double the one on its right, and the number is the sum of the places holding a 1. The "why" in AC9TDI8K04 is the last Worked example task: two states are easy to tell apart reliably.

This lesson uses no code. Students who have done the coding lessons have met bits as micro:bit LEDs (on or off) and as True or False.

Running the lesson

  1. Predict: students who chose 1011 read it as a base-10 number; 3 counted the 1s.
  2. Try: ask which card is worth the most, and why it is on the left (like the thousands column).
  3. Worked example: have students say the places aloud from the right before revealing line 2.
  4. Vary: before 7 to 8, ask students to predict how many cards will change.
  5. Make: collect answers and the stretch (7, 00111): what is the difference?

The hard part (on purpose)

Reading binary as an ordinary number (1011 as one thousand and eleven). Have students say binary digit by digit ("one zero one one") and point at each card's value as they add.

When students get stuck

Stretch and support

Stretch: Count from 0 to 15 in binary on four cards. Which card flips every time? Which flips every second time? Every fourth?

Support: Keep the card values (16 8 4 2 1) written above every binary number until reading them is automatic.

Where it leads

Next: How many patterns? (how many numbers a set of bits can hold, and overflow).

Where it leads: the 0 to 255 limits students met in text, colours and sound come from bits (How many patterns?). Later: why binary (logic gates) and how bits underpin every encoding. In maths, the places are powers of 2, as base-10 places are powers of 10.

Sources

What each step is for

Now you can
Next lesson6. How many patterns?Each extra bit doubles the number of patterns: n bits make 2ⁿ patterns. One pattern is 0, so the largest number is 2ⁿ − 1: four bits hold 0 to 15, eight bits (a byte) hold 0 to 255. Count one past the largest and the bits overflow back to 0.