doPhysics.in
All chapters

Logic Gates: NOT, AND, OR

14 min read3 ideas6 checks2 figures to playBy Asheshanand Acharya
What you will learn 0 / 3
Binary levels and truth tables
Look around
A calculator that only switches

Type \(7 + 5\) on a cheap pocket calculator and it shows \(12\) at once. Inside there are no gears and no counting beads. There are only thousands of tiny switches, each either on or off. Somehow on and off, arranged the right way, can add.

you will build, from the gates of this lesson, the circuit that adds two binary digits, the first step of every sum a calculator does.

Two levels, 0 and 1

A signal that can take any value, like the output of a microphone, is an analogue signal. A digital signal takes only two values. In the circuits of this lesson a voltage near \(0\,\text{V}\) is the level \(0\), or low. A voltage near \(5\,\text{V}\) is the level \(1\), or high. The exact voltage does not matter, only which of the two ranges it lies in. That makes digital circuits very tolerant of noise.

With two levels, numbers are written in binary, with the digits \(0\) and \(1\) only. Each place is worth twice the place to its right: \(1, 2, 4, 8, \dots\). So \(7\) is \(111\), \(5\) is \(101\), and \(12\) is \(1100\). A calculator works on numbers in this form.

definition 8.4
Logic gate and truth table

A logic gate is a circuit with one or more inputs and one output, each at level \(0\) or \(1\). A logical rule fixes the output from the inputs. Its truth table lists the output for every possible combination of inputs.

Each input has two possible levels. So a gate with two inputs has \(2 \times 2 = 4\) input combinations, one with three inputs has \(8\), and one with \(n\) inputs has \(2^n\). Write them in the order of counting in binary, \(00, 01, 10, 11\), so that none is missed.

Checkpoint · numericUnanswered

How many rows does the truth table of a gate with four inputs have?

± 2 %
Not and and or gates

The three basic gates

The NOT gate has one input and gives the opposite level: \(0\) becomes \(1\), and \(1\) becomes \(0\). Its output is written \(Y = \bar A\), read "A bar" or "not A". The AND gate gives \(1\) only when all its inputs are \(1\); its output is written \(Y = A \cdot B\). The OR gate gives \(1\) when any input is \(1\), or more than one; its output is written \(Y = A + B\).

NOT, AND and ORThree logic gates side by side, each with its inputs on the left and its output on the right: NOT, with the single input A; AND and OR, with the inputs A and B. A wire at 1 is drawn thick and green, a wire at 0 thin and grey, with its digit at the end. Chips set the inputs to 0 0, 0 1, 1 0 and 1 1. NOT always gives the opposite of A. AND gives 1 only when A and B are both 1. OR gives 1 when A or B, or both, is 1.01NOT Y = NOT A 000AND Y = A · B 000OR Y = A + B
Fig 5.1The symbols of the NOT, AND and OR gates. A wire at level \(1\) is drawn thick and green, a wire at \(0\) thin and grey. Choose each chip in turn and compare the outputs with the truth tables below.

The symbols in Fig 5.1 are the standard ones. NOT is a triangle with a small circle, the inversion bubble, at its output. AND has a flat back and a round front. OR has a curved back and a pointed front. The expressions \(A \cdot B\) and \(A + B\) are the notation of Boolean algebra. The dot is read "and", and the plus is read "or"; they are not ordinary multiplication and addition.

The three truth tables fit side by side: \[ \begin{array}{cc|c|c|c} A & B & \bar A & A \cdot B & A + B \\ \hline 0 & 0 & 1 & 0 & 0 \\ 0 & 1 & 1 & 0 & 1 \\ 1 & 0 & 0 & 0 & 1 \\ 1 & 1 & 0 & 1 & 1 \end{array} \] Read down each column. AND has a single \(1\), in the last row. OR has a single \(0\), in the first row.

RememberThe three basic gates
\[ \text{NOT: } Y = \bar A, \qquad \text{AND: } Y = A \cdot B, \qquad \text{OR: } Y = A + B \]
Holds whenfor inputs and outputs at the logic levels \(0\) and \(1\). AND and OR take any number of inputs: \(A \cdot B \cdot C\) is \(1\) only if all three are \(1\), and \(A + B + C\) is \(0\) only if all three are \(0\).
Symbols\(A\), \(B\) the inputs, \(Y\) the output; the bar means NOT, the dot AND, the plus OR
Unitsnone; every quantity is \(0\) or \(1\)

Series and parallel switches

Two switches and a lamp show the same two rules. Let a closed switch be \(1\) and a lit lamp be \(1\). With the switches in series, current flows only if both are closed: the circuit is an AND gate. With the switches in parallel, current flows if either is closed: the circuit is an OR gate.

ExampleThe seat-belt warning

A car sounds a warning when the engine is running (\(E = 1\)) and the driver's seat belt is not fastened (\(S = 0\)). Write the expression for the warning \(W\), and name the gates needed. Check it for a fastened belt.

Try it on paper first. The solution is one tap away when you are ready.

A few rules of Boolean algebra

Since every quantity is \(0\) or \(1\), a few rules follow straight from the tables. Check each against the truth tables: \[ A + 0 = A, \quad A + 1 = 1, \quad A \cdot 0 = 0, \quad A \cdot 1 = A \] \[ A + A = A, \quad A \cdot A = A, \quad A + \bar A = 1, \quad A \cdot \bar A = 0, \quad \bar{\bar A} = A \] The last three say three things. A statement and its opposite are never both true. One of them always is. Inverting twice changes nothing.

CheckpointUnanswered

What is the value of \(A + 1\) in Boolean algebra?

Checkpoint · numericUnanswered

A three-input AND gate and a three-input OR gate are given the same inputs \(A\), \(B\), \(C\). For how many of the eight input combinations do their outputs agree?

± 2 %
Gates built from diodes and a transistor

Gates made of diodes

A gate is a circuit, and the simplest ones need only diodes and a resistor. Take the inputs as \(0\,\text{V}\) or \(5\,\text{V}\), and ignore the small drop across a conducting diode. In the diode OR gate, each input feeds the anode of a diode, and the cathodes meet at the output \(Y\). A resistor joins \(Y\) to \(0\,\text{V}\).

Gates made of diodesTwo gates built from two diodes and a resistor, with inputs of 0 volts, logic 0, or 5 volts, logic 1; the small drop across a conducting diode is ignored. Left, the OR gate: the anodes take the inputs and the cathodes meet at the output Y, with a resistor from Y to 0 volts. A diode with 5 volts on it conducts and lifts Y to 5 volts. Right, the AND gate: the cathodes take the inputs and the anodes meet at Y, with a resistor from Y up to 5 volts. A diode with 0 volts on it conducts and pulls Y down to 0 volts. Chips set the inputs; a conducting diode is filled green.diode OR gate diode AND gate 0 V 0 V 0 V A B Y Y = 0 V, logic 0 +5 V 0 V 0 V A B Y Y = 0 V, logic 0
Fig 5.2Two gates made of two diodes and a resistor. Left, the OR gate; right, the AND gate. Choose the input chips; a conducting diode is filled green. A diode conducts when its anode is higher than its cathode.

In the OR gate of Fig 5.2, suppose \(A\) is at \(5\,\text{V}\) and \(B\) at \(0\,\text{V}\). The upper diode has \(5\,\text{V}\) on its anode, so it conducts and lifts \(Y\) to \(5\,\text{V}\). The lower diode now has \(0\,\text{V}\) on its anode and \(5\,\text{V}\) on its cathode. It is reverse-biased and off. If both inputs are at \(0\,\text{V}\), neither diode conducts, and the resistor holds \(Y\) at \(0\,\text{V}\). One high input is enough: an OR gate.

Turn both diodes round and join the resistor to \(+5\,\text{V}\) instead. Now a low input makes its diode conduct and pulls \(Y\) down to \(0\,\text{V}\). Only when both inputs are at \(5\,\text{V}\) does no diode conduct, so the resistor holds \(Y\) at \(5\,\text{V}\). That is the AND gate on the right of the figure.

A NOT gate from a transistor

Diodes alone cannot invert, but a transistor can. The input drives the base through a resistor, and a resistor joins the collector to the \(5\,\text{V}\) supply; the output is taken at the collector. A high input sends current into the base and turns the transistor fully on, pulling the collector nearly to \(0\,\text{V}\). A low input leaves it off, so no current flows in the collector resistor and the collector stays at \(5\,\text{V}\). Lesson 4 follows this switch in detail.

CheckpointUnanswered

In the diode OR gate, input \(A\) is at \(0\,\text{V}\) and input \(B\) at \(5\,\text{V}\). Which diode conducts, and what is the output?

Adding two binary digits

Now return to the calculator. Adding two one-digit binary numbers \(A\) and \(B\) gives a sum digit \(S\) and a carry digit \(C\). In binary, \(1 + 1 = 10\): sum \(0\), carry \(1\). The four cases are: \[ \begin{array}{cc|cc} A & B & C & S \\ \hline 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & 0 & 1 \\ 1 & 1 & 1 & 0 \end{array} \] The carry column is AND: \(C = A \cdot B\). The sum column is \(1\) only when the inputs differ.

The sum is written \(S = A \cdot \bar B + \bar A \cdot B\): "A and not B, or not A and B". It is built from two NOT gates, two AND gates and one OR gate. This combination is so useful that it has its own name and symbol, the XOR gate, exclusive OR, written \(S = A \oplus B\). An XOR gate and an AND gate together make a half adder. A calculator chains such adders, one for each binary place, and \(7 + 5\) becomes \(111 + 101 = 1100\), twelve.

definition 8.5
XOR gate

The exclusive OR, or XOR, gate gives \(1\) when its two inputs differ and \(0\) when they are the same: \(Y = A \oplus B = A \cdot \bar B + \bar A \cdot B\). Its truth table is \(0, 1, 1, 0\) for the inputs \(00, 01, 10, 11\).

Checkpoint · select all that applyUnanswered

Which of these statements about the XOR gate are true?

Checkpoint · in your own wordsUnanswered

A NOT gate is made from a transistor with a resistor from its collector to a \(5\,\text{V}\) supply. Explain why a high input gives a low output.

Story · George Boole and Claude Shannon, 1854 and 1937
From the laws of thought to switches

In 1854 George Boole, a self-taught teacher of mathematics in Ireland, published The Laws of Thought. It turned logical reasoning into an algebra of true and false, the algebra of this lesson. For eighty years it looked like pure philosophy. Then in 1937 Claude Shannon, a student in America, showed that circuits of relay switches obey exactly Boole's rules. Every digital circuit since has been designed with them.

In the world
The staircase light

Many Indian homes light a staircase with one lamp and two switches, one at the bottom and one at the top. Either switch turns the lamp on or off, whatever the other is doing. With each switch position called \(0\) or \(1\), the lamp is lit when the two switches differ. The staircase light is an XOR gate, built from two two-way switches and a wire.

Exam traps
  1. Reading \(A + B\) as ordinary addition.
    In Boolean algebra + means OR, so \(1 + 1 = 1\).
  2. Missing rows in a truth table.
    List all \(2^n\) rows in binary counting order: \(00, 01, 10, 11\).
  3. Confusing OR with XOR.
    They differ only in the row \(11\): OR gives \(1\), XOR gives \(0\).