The purpose of this module is to explore digital logic gates.
Logic gates are the building blocks of computer chips.
We will also learn about Boolean logic, the math behind these logic gates.
Boolean logic is how we program computers to make decisions.
Prerequisite Modules:
Upon completion of this module, you should be able to:
In the world of electronics there are two major types of signals:
An electronic analog signal varies over time and can have a different value at any given time.
An electronic binary signal can also vary over time, but it can only be used to represent two separate levels.
The digital circuits that make up all modern computers use binary signals for communication and for information storage.
Some reasons for why modern computers use binary signals (as opposed to analog signals):
In electronic circuits binary zero is represented by a low voltage (near zero volts) and binary 1 is represented by a high voltage (often five volts).
Boolean logic is a type of algebra where the variables can only take two possible values. These values are 1 and 0, although we sometimes refer to these as true and false respectively. In other words, Boolean logic is an algebra for binary systems.
As we saw in the history module, Boolean logic was developed by George Boole in the 1840s and was later implemented electronically by Claude Shannon (right) in the 1930s, leading to the advent of electronic computers.
At the heart of nearly all electronic circuits lies this system of Boolean calculation.
Instead of studying Boolean algebra on it’s own, we will study the digital components used in electronic circuits that implement Boolean algebra operations.
These components are called digital logic gates. We will be using the symbols shown to the right to represent these gates.
The lines leading to the left of each gate represent input wires, while the line leading from the right of each gate represents the output.
You can think of each gate as performing an algebraic operation on its inputs to create its output. The inputs and outputs will always be the binary values of either true or false.
Imagine a house with a doorbell. When the doorbell button is pressed a chime will be heard within the house.
We can model this as a Boolean system:
(Doorbell Chime) = (Doorbell button pressed)
Many cars will signal a buzzer if the engine is on and the driver’s seat-belt is undone.
Modeled as a Boolean System:
Buzzer = (Engine is On?) AND (Seat-belt is Undone?)
Stated another way:
Buzzer = (Engine is On?) AND (Seat-belt is NOT Fastened?)
A truth table is a mathematical table used in Boolean Logic to represent all possible combinations of input and output.
Let’s describe our seat-belt example as a truth table:
A = Engine is On? (True or False)
B = Seat-belt is Undone? (True or False)
X = Turn on buzzer. (True or False)
| A | B | X |
-------------
| F | F | F |
| F | T | F |
| T | F | F |
| T | T | T |
In other words, the buzzer will only sound when both A and B are True.
Another way to build this truth table would be using zeros and ones:
| A | B | X |
-------------
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Wikipedia Links
The simplest logic gate is the NOT gate, sometimes called an inverter.
The truth table for a NOT gate:
| A | X |
---------
| F | T |
| T | F |
In other words, X is true when A is NOT true.
An AND gate has two inputs and one output.
The output is always false, unless both inputs are true.
The truth table for an AND gate:
| A | B | X |
-------------
| F | F | F |
| F | T | F |
| T | F | F |
| T | T | T |
In other words, X will be true when both A AND B are true.
Does this truth table look familiar? (Hint: Compare it to our selt-belt example.)
Wikipedia Links:
An OR gate has two inputs and one output.
The output is always true, unless both inputs are false.
The truth table for an OR gate:
| A | B | X |
-------------
| F | F | F |
| F | T | T |
| T | F | T |
| T | T | T |
In other words, X will be true when both A OR B are true.
An XOR gate has two inputs and one output.
The output is true, unless both inputs are the same.
The truth table for an XOR gate:
| A | B | X |
-------------
| F | F | F |
| F | T | T |
| T | F | T |
| T | T | F |
In other words, X is true when A is NOT equal to B.
It is common in digital circuit design for a NOT gate to follow directly after one of the other gate types.
To simplify our circuit diagrams there are a series of negated gates to use in this situation.
A NAND gate has two inputs and one output. It is equivalent to an AND gate followed by a NOT gate.
The output is always true, unless both inputs are true.
The truth table for an NAND gate:
| A | B | X |
-------------
| F | F | T |
| F | T | T |
| T | F | T |
| T | T | F |
A NOR gate has two inputs and one output. It is equivalent to an OR gate followed by a NOT gate.
The output is always false, unless both inputs are false.
The truth table for an OR gate:
| A | B | X |
-------------
| F | F | T |
| F | T | F |
| T | F | F |
| T | T | F |
An XNOR gate has two inputs and one output. It is equivalent to an XOR gate followed by a NOT gate.
The output is true, when both inputs are the same. For this reason it is sometimes called an equality gate.
The truth table for an XNOR gate:
| A | B | X |
-------------
| F | F | T |
| F | T | F |
| T | F | F |
| T | T | T |
Gates can be chained together to create more complex structures.
The truth table for the system to the right:
| A | B | C | X |
-----------------
| F | F | F | F |
| F | F | T | F |
| F | T | F | T |
| F | T | T | F |
| T | F | F | T |
| T | F | T | F |
| T | T | F | T |
| T | T | T | F |
In other words, X will be true whenever A OR B is true unless C is true.
A friendlier way to look at this truth table would be to change the positions of columns and replace the T/F for 1/0:
| C | A | B | X |
-----------------
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
Here it is more obvious that X is false anytime C is true, and that when C is false X will be true if either A or B is true.
How would the truth table change if the OR gate was replaced by an XOR?
Let’s see how these digital logic gates can be used to implement two useful combinational circuits:
Two Digital Logic Simulators:
Ticket Time Problem
You are driving to school and you pass a speed trap. If your speed is 60 or less, you arrive at school without incident. If your speed is 61 or greater, you’ll get a speeding ticket.
A Boolean logic equation that describes the above situation might be:
Ticketed = (Driving speed is greater than 60.)
Let’s add a twist to the ticketing rules:
On your birthday your speed can be 5 higher than the regular speed limit.
What might the Boolean logic equation for ticketing look like now?
Boolean logic is not only used at the circuit level, it is also used for all decisions made in computer programs.
Armed with our knowledge of Boolean logic we can now begin to exploring problem solving with algorithms.