## Boolean logic

### Introduction

The CPU (central processing unit) is often called the brain of the computer because that is where all of the ‘thinking' is done, program instructions are executed, calculations are carried out and decisions are made.

Our brains use nerve cells to do this, but the CPU has to make do with transistors, billions of them. Each one acts as a switch: it either transmits electricity or it doesn't. It is binary as it has two states, on or off, which can be represented as 1 and 0 or true and false. Only using two values doesn't sound like it's going to solve many problems, does it?

Fortunately, the transistors can be built into circuits called logic gates that can then be combined into more complex circuits. Logic gates can take one or more inputs and either produce an output or not according to the way they have been wired up. So when the CPU has a complex problem involving Boolean operators like this to solve…
if X == 3 AND NOT(Y == 6) OR X != 10 AND Y == 9 then
…it can use its transistor logic circuits.

When we try to work out something like that, we have to rely on the logic circuits (neurons) in our heads. But we can use truth tables to help us. These let us look at all of the possible inputs and the outputs that would be generated.