← Data representation

Why binary: logic gates

A switch has two states that are easy to tell apart: off (0) and on (1). Wire two switches in a line and the lamp lights only when both are on: an AND gate. Side by side, either one will do: an OR gate. Gates like these, made of tiny electronic switches, combine bits to do every calculation, which is why computers are built on binary.

A computer chip holds billions of tiny switches and nothing else. How can switches add up numbers?

In the binary lessons, each bit was a card face up or face down. Inside a computer, a bit is a tiny electronic switch: off (0) or on (1). Two states are easy to tell apart, even when the signal is a little weak or noisy. Switches can also be wired together so that some bits control other bits. That is how a computer calculates.

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

Two switches in a line

A battery, two switches and a lamp are wired in one loop, one switch after the other. Switch A is **on** and switch B is **off**. Does the lamp light?

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

Try: every combination

Was your prediction right? Look at the truth table: one row in four lights the lamp.

Try it yourselfYour edits are saved in this browser.

Click the switches to try all four combinations of A and B. When does the lamp light?

Use the board. This ticks when you get there.

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

Worked example: AND and OR

Worked exampleBefore each step, say what you think comes next.
  1. AND:0 0→0,0 1→0,1 0→0,1 1→1\text{AND}: 0\,0 \to 0,\quad 0\,1 \to 0,\quad 1\,0 \to 0,\quad 1\,1 \to 1Switches in a line: the output is 1 only when both inputs are 1.

Now read an OR gate.

Two switches side by side (an **OR** gate). A = 1 and B = 0. What is the output?

Sam fills in the OR gate's truth table. Click the line where it first goes wrong.

Why are computers built on binary, not on ten levels for the digits 0 to 9?

ModifyChange the problem on purpose and see what happens.

Vary: change the gate

Try it yourselfYour edits are saved in this browser.

Switch the gate to OR. Turn on only A. What is the output?

Use the board. This ticks when you get there.

Keep OR and turn B on too.

Use the board. This ticks when you get there.

Switch to NOT. Turn A off. What comes out?

Use the board. This ticks when you get there.

Switch back to AND and make the output 1.

Use the board. This ticks when you get there.

An AND gate has A = 0. Does it matter what B is?

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

Gates

What is **1 AND 0**?

What is **NOT 1**?

A car alarm should sound if the door is opened **or** the window is broken. Which gate?

A machine should run only when the guard is closed **and** the start button is pressed. Which gate?

Review: what number is **110** in binary?

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

Add two bits

Stretch: which inputs give the answer 01? Why are there two ways?

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

The adder shows A + B as a two-bit binary number: carry, then sum.

Another hint

10 in binary is 2. Which inputs add to 2?

Another hint

Turn both switches on.

This circuit adds two bits: the sum is A XOR B and the carry is A AND B. Set the switches so the answer is 10 in binary (2).

Use the board. This ticks when you get there.

For teachers

Students try every combination of two switches in a circuit to build AND and OR truth tables, use NOT, then add two bits with a half adder, to explain why digital systems are built on binary (AC9TDI8K04 node 3). About 40 minutes.

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

Students will be able to

Before class

Try the boards yourself. A torch, a battery and two real switches (or a breadboard) make the Try concrete in a minute.

The one idea (the kit's chain for this node): electronic components have two reliable states → those states are 0 and 1 → gates combine them → so binary is the foundation of all computing. The half adder in Make shows gates doing the binary addition students know from lesson 5.

Simplifications: real gates are made of transistors, not mechanical switches; the circuit view is an analogy that holds for AND and OR.

Running the lesson

  1. Predict: students who chose "yes" picture parallel wiring. Ask them to trace the current.
  2. Try: have students fill a paper truth table as the board's fills.
  3. Worked example: before the OR line, ask what changes when the switches sit side by side.
  4. Vary: ask why AND has only one row that gives 1.
  5. Make: connect to 1 + 1 = 10 in binary and to carrying in base 10.

The hard part (on purpose)

Students read OR as everyday English (one or the other, not both). Point at the circuit: with both switches on, is there still a path for the current?

When students get stuck

Stretch and support

Stretch: A full adder adds three bits (two numbers and a carry in). Sketch how two half adders and an OR gate could make one.

Support: Keep the three truth tables on the board for the whole lesson.

Where it leads

Next: Bits all the way down (tracing text and colours to binary).

Code links: and, or and not in Python and MakeCode conditions are these gates; the Robotics course uses them to combine sensor readings.

What each step is for

Now you can
Next lesson8. Bits all the way downEvery kind of data ends up as bits: a character becomes its code, and the code becomes 8 bits (A is 65, which is 01000001). A pixel is three codes, so 24 bits. The chain is always the same: data, then numbers, then binary.