Logic diagrams
Introduction
We know from an earlier section that computers are made up of millions and millions of switches. These switches can be grouped together to form codes. These codes can be used to represent any piece of data. We can also use these switches to control what happens in a computer. A computer needs to be able to say things like:
-
- if both this switch and that switch is on, then do this action.
- if either one of these switches is on, do this action.
- if this switch is on, don't do that action. If it is off, do that action.
These kinds of sentences use 'logic'. So that we don't have to write down long logic sentences, there are diagrams known as 'logic diagrams' that summarise neatly what sets of logic sentences. The component parts of a logic diagram are 'logic gates'.
Logic gates
Logic diagrams are made up of a number of smaller diagrams, known as 'logic gates'. A logic gate is a hardware component that has some inputs and an output and the gate controls the output depending upon the inputs. You can combine these gates into complicated electronic circuits, which are then added to other components into an 'integrated circuit'. You may have handled integrated circuits - that's what a CPU or a RAM is.
Each logic gates has at least one input and only a single output, which depends on the inputs. If a logic diagram has a total of two inputs, then there are two to the power two = 4 possible unique combinations of inputs. If a logic diagram has a total of three inputs, then there are two to the power three = 8 possible unique combinations of inputs. If a logic diagram has a total of four inputs, then there are two to the power four = 16 possible unique combinations of inputs. If a logic diagram has a total of S inputs, then there are two to the power S possible unique combinations of inputs. This is useful to know because it helps you draw up a truth table for any diagram!
Before we look at more complicated diagrams, let's look at the basic logic gates first. The most important to get to know are the AND, OR and NOT logic gates.
The AND logic gate
This logic gate gives an output if *all* of the inputs are true. If any of the inputs are false then the output is a zero.
This kind of logic can be applied to all manner of situations apart from a computer. For example, pupils should stand up if they own a bicycle and own a skateboard. The output is 'standing up'. The inputs are 'owning a bicycle' and 'owning a skateboard'. You only stand up if you both own a bicycle AND you own a skateboard. This situation could be represented using the AND logic gate easily, rather than trying to write out accurately who should stand up.
We can represent all of the different possible situations using a 'truth table'. The truth table for the AND gate looks like this:
It simply shows the output for every possible permutation for the AND gate.
The OR logic gate
This logic gate gives an output if *either* of the inputs are true (or both of them are true). If both of the inputs are false then the output is a zero.
Using our example from before, pupils should stand up if they own a bicycle OR own a skateboard. The output is 'standing up'. The inputs are 'owning a bicycle' and 'owning a skateboard'. You stand up if you either own a bicycle OR you own a skateboard (or indeed if you own both). You stay seated if you neither own a bicycle nor own a skateboard. Again, this situation could be represented using the OR logic gate easily, rather than trying to write out accurately who should stand up and who should stay in their seat.
We can represent all of the different possible situations using a 'truth table'. The truth table for the OR gate looks like this:
It shows the output for every possible permutation for the OR gate.
The NOT logic gate
This logic gate only has one input. If the input is true, the output if false. If the input is false, the output is true. The truth table for the NOT gate looks like this: