Computers and computer programs are all about solving problems. In order to solve problems, we need to understand the idea of logic – what happens when something and/or something else happens.

To see how this works inside a computers architecture we can draw logic circuits using logic gates.

In this lesson, we’ll learn about:

- What logic gates are
- Logic diagrams using AND
- Logic diagrams using OR
- Logic diagrams using NOT

## 1. What Logic Gates Are

If you look at your lights in your classroom, it can be in one of two states – it’s either ON or OFF.

Your lights are controlled by a switch on the wall. If the switch is ON, the lights are ON. If the switch is OFF, the lights are OFF. There is no such concept as ‘sort of on’.

The way this works is that when you press a switch, you close an electrical circuit allowing current to flow to the lights.

This is shown in figure 1.

If you turn off a light, you are opening a switch, meaning electrical current cannot flow to the light.

Much like your light switch, computers are made up of switches too.

In the Computer Systems unit of your GCSE you learn how computers work entirely in binary. Binary is the number system entirely made up of 1’s and 0’s.

Inside of your computer, in your RAM memory and inside your CPU there are billions of tiny switches that are storing 1’s and 0’s by being either open of shut. That’s how your computer works.

Logic gates represent how these switches are used in computers. By combining these logic gates we create circuits, just like the circuits in your computer which give you the ability to store a file or play a video game, all by turning on and off switches.

### Further Thought

What would happen if a switch was locked open or shut? What would that mean for the data stored there.

## 2. Logic Diagrams Using AND

There are three basic types of logic gates. The first of these we’ll learn is an AND gate. This looks like figure 2 below.

You can see in the image above that this AND gate will take two inputs and give one output. When BOTH this logic gates inputs are 1 (remember, computers only use 1’s and 0’s) then it will output a 1. Otherwise, it will output a 0.

It can be beneficial to think of this in terms of switches and a lightbulb. Imagine you had two switches in a line, as shown in figure 3.

Both switches are open (turned off), so no power can reach the light bulb, so the light bulb is turned off. As we’ve learnt, your computer is just made up of switches, when they’re open they represent a 0 and when they’re closed they represent a 1.

So here we have two 0’s, leading to no electricity reaching our lightbulb (which we can also think of as a 0).

Now let’s say we close ONE of the switches.

One switch is now closed (turned on) and so it passes power through it. This represents a binary 1. However, the second switch is open, so the power cannot reach the lightbulb and so it’s still turned off.

Finally, we close BOTH of the switches.

Both switches are closed, representing binary 1’s. This means power can reach our lightbulb and it turns on, representing an output of binary 1.

### Further Thought

Can you think of any programs that you have written that need the AND operator? Can you write the circuit diagram?

## 3. Logic Diagrams Using OR

The next type of logic gate is an OR gate. This looks like figure 6 below.

You can see in the image above that this OR gate will take two inputs and give one output. When EITHER this logic gates inputs are 1 then it will output a 1. Otherwise, it will output a 0.

Let’s see how this looks in terms of the switches and lightbulb example. Instead of having two switches in a line, we have two separate lines with switches on them, as shown in figure 7.

Both switches are open (representing 0’s), so no power can reach the light bulb. This means the light bulb is turned off (representing a 0).

Now let’s say we close ONE of the switches.

One switch is now closed and so it passes power through it. This represents a binary 1. The second switch is open, but the power can still reach the lightbulb and so it’s now turned on, representing an output of binary 1.

Finally, we close BOTH of the switches.

Both switches are closed, representing binary 1’s. This means power can still reach our lightbulb and it turns on, representing an output of binary 1.

### Further Thought

Can you think of any programs that you have written that need the OR operator? Can you write the circuit diagram?

## 4. Logic Diagrams Using NOT

The final of the three basic types of logic gate is the NOT gate. This looks like figure 10 below.

This differs from the other types of gate diagrams as it only has one input and one output.

When a NOT gate has an input of 1, it gives an output of 0. When it has an input of 0, it gives an output of 1.

We can’t really represent this with our light bulb analogy. It would be like someone had wired the light switch the wrong way so that when you turned it OFF the lights went ON.

### Further Thought

Can you think of any programs that you have written that need the NOT operator? Can you write the circuit diagram?

## Lesson Summary

So to summarise what we’ve learnt in this lesson:

- Electrical switches can either be ON or OFF, corresponding to a 1 or a 0.
- An AND gate returns a 1 if both its inputs are a 1. Otherwise it returns a 0.
- An OR gate returns a 1 if either its inputs are a 1. Otherwise it returns a 0.
- A NOT gate flips the input, so a 1 becomes a 0 and vice versa.