Circuit 3D

Logic gates

Logic gates are the building blocks of digital circuits: each takes one or more binary inputs, 0 or 1, and gives a single output by a fixed rule. An AND gate outputs 1 only when all its inputs are 1, an OR gate when any is, and a NOT gate flips its one input, so 1 AND 0 is 0 while 1 OR 0 is 1.

AND: Y = A · B   OR: Y = A + B   NOT: Y = A̅

where A and B are the inputs, Y the output, and · and + mean AND and OR, not multiply and add.

Every gate’s behavior fits in a truth table, and gates combined make adders, memory and processors. In a chip, each gate is a handful of transistors.

What is a logic gate?

A logic gate is a circuit that takes binary inputs, each 0 or 1, and gives one output by a simple rule, such as AND, OR or NOT.

They are how digital electronics decides: a door alarm that sounds if the door is open AND the system is armed is an AND gate. In Figure 1, pick a gate and its inputs; the lamp shows the output.

A 1B 1 1 ABOut 000 010 100 111

AND: its output is 1 only when both inputs are 1. With A = 1 and B = 1, the output is 1.

Figure 1. A logic gate and its truth table. Orange wires are 1, grey are 0; the highlighted row is the one the inputs pick.

What are the seven basic logic gates?

The seven basic logic gates are AND, OR and NOT; NAND and NOR, which are AND and OR with the output inverted; and XOR and XNOR, which compare their inputs.

GateOutput is 1 whenExpression
ANDboth inputs are 1A · B
OReither input is 1A + B
NOTits one input is 0A̅
NANDnot both inputs are 1NOT (A · B)
NORboth inputs are 0NOT (A + B)
XORthe inputs differA ⊕ B
XNORthe inputs matchNOT (A ⊕ B)

What is a truth table?

A truth table lists every combination of a gate’s inputs and the output each one gives, so a two-input gate’s table has 4 rows and describes the gate completely.

A truth table has a row for each combination: 2 for one input, 4 for two, and 2n for n inputs. Any logic circuit, however large, has a truth table too, which is how designers check it.

Why is the NAND gate called universal?

The NAND gate is called universal because NAND gates alone can build NOT, AND and OR, and so every other gate and any digital circuit, as Boolean algebra proves.

Tie a NAND’s inputs together and it becomes NOT; follow a NAND with NOT and it becomes AND; invert both inputs first and it becomes OR. NOR gates can do the same. Chip makers like NAND because it is simple and fast to build.

A 0 B 1

OR from NANDs: two NANDs invert A and B, to 1 and 0, and a third NANDs them: NAND(1, 0) = 1, the same as OR gives: 1.

Figure 2. NOT, AND and OR made from NAND gates and nothing else. Every input gives the same output as the real gate.

What is an XOR gate used for?

An XOR gate outputs 1 when its inputs differ, which is exactly the sum digit when adding two binary digits, so it sits at the heart of every adder.

Paired with an AND gate for the carry, it makes a half adder; chained adders add whole binary numbers. XOR also checks whether two signals match and computes parity bits for error checking.

A 1 B 1 Sum 0 Carry 1

1 + 1 = 2, which is 10 in binary: the XOR gives the sum digit, 0, and the AND the carry, 1.

Figure 3. A half adder adds two binary digits with one XOR gate and one AND gate.

How are logic gates made?

Logic gates are made from transistors used as switches: in modern CMOS chips, each gate is a few MOSFETs that connect the output to the supply for a 1 or to ground for a 0.

Older TTL chips use bipolar transistors. A 1 is a voltage near the supply and a 0 near ground: on 5 V TTL, an input reads 1 above 2 V and 0 below 0.8 V. The 7400 chip holds four NAND gates.

How do you work out a logic circuit?

To work out a logic circuit, start at the inputs and go forward one gate at a time, writing each gate’s output before the next uses it. With A = 1 and B = 0, (A OR B) AND NOT (A AND B) works out to 1.

Example 1: work through a gate circuit

A circuit computes Y = (A OR B) AND NOT (A AND B). What is Y when A = 1 and B = 0?

Given
A = 1, B = 0, and Y = (A OR B) AND NOT (A AND B)
Find
Y
Solution
A OR B = 1 OR 0 = 1A AND B = 1 AND 0 = 0, so NOT (A AND B) = 1Y = 1 AND 1 = 1, the same as A XOR B = 1
Answer
Y = 1

Example 2: add two binary numbers with gates

Add X = 3 and Y = 1, each written as two binary digits, using a half adder for the first digit and a full adder for the second.

Given
X = 3 = 11 and Y = 1 = 01 in binary
Find
X + Y, bit by bit
Solution
Bit 0, a half adder: sum 1 XOR 1 = 0, carry 1 AND 1 = 1Bit 1, a full adder: sum 1 XOR 0 XOR 1 = 0, carry 1Reading carry, bit 1, bit 0: 100
Answer
11 + 01 = 100, which is 4

Summary

Key equations

  • Y = A · B AND
  • Y = A + B OR
  • Y = A ⊕ B XOR
  • rows = 2n a truth table with n inputs

Key terms

Truth table
Every input combination and its output.
Universal gate
One that can build all the others: NAND or NOR.
Half adder
XOR and AND, adding two bits.
Logic level
The voltage that counts as 0 or 1.

Practice problems

  1. An AND gate has inputs 1 and 0. What is its output?

  2. Which gate outputs 1 only when its two inputs differ?

  3. How many rows does the truth table of a 3-input gate have?

  4. A NAND gate has both inputs at 1. What is its output?

  5. Which single gate type can be used to build every other gate?

FAQ

What is an OR gate?

A gate whose output is 1 when any of its inputs is 1, and 0 only when all are 0, like two switches wired in parallel.

What is the difference between NAND and AND?

A NAND gate is an AND gate followed by NOT: its output is 0 only when every input is 1, and 1 otherwise.

What is an XOR gate?

An exclusive OR: its output is 1 when exactly one of its two inputs is 1. It adds binary digits and checks whether signals differ.

What is a NOR gate?

An OR gate followed by a NOT: its output is 1 only when every input is 0. Like NAND, it is universal, able to build every other gate on its own.

What is an XNOR gate?

An XOR gate followed by a NOT: its output is 1 when its two inputs are the same, which makes it an equality checker.

What is a NOT gate?

An inverter: its single output is the opposite of its input. Its symbol is a triangle with a small circle, and that circle on any gate’s output means NOT.

Which chips contain logic gates?

The 7400 series: the 7400 holds four NAND gates, the 7408 four AND gates, the 7432 four OR gates, the 7402 four NOR gates, the 7404 six NOT gates and the 7486 four XOR gates.

What are the logic gate symbols?

AND is a D shape, OR a curved shield and NOT a triangle with a small circle on its output; that circle inverts, turning AND into NAND and OR into NOR, and XOR adds a second curve across the inputs.