Logic Gates
Learn how AND, OR, NOT, XOR, NAND and NOR gates turn 1s and 0s into decisions, and how to find the output of a small circuit.
Definition
- 1 = voltage on (high), which means true
- 0 = voltage off (low), which means false
| AND | OR | XOR | NAND | NOR | ||
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 |
- AND: output 1 only when both inputs are 1
- OR: output 1 when at least one input is 1
- XOR (exclusive OR): output 1 when the inputs are different
- NAND (NOT AND): the opposite of AND, output 0 only when both inputs are 1
- NOR (NOT OR): the opposite of OR, output 1 only when both inputs are 0
Try it now
Worked Examples
The inputs are and . Find the output of an AND, OR, XOR, NAND and NOR gate.
AND gate
AND needs both inputs to be 1, but → AND:
OR gate
OR needs at least one 1, and → OR:
XOR gate
The inputs and are different → XOR:
NAND gate
NAND is the opposite of AND: AND gave , so flip it → NAND:
NOR gate
NOR is the opposite of OR: OR gave , so flip it → NOR:
Answer: AND , OR , XOR , NAND , NOR . NAND and NOR are always the opposite of AND and OR.
Common Mistakes
Thinking an OR gate gives when both inputs are
Why it's wrong: That is the XOR gate. OR is 1 when at least one input is 1, and that includes the case where both are 1.
Correct: OR: . XOR: . Only XOR asks for the inputs to be different.
Reading as ordinary addition and writing
Why it's wrong: In gate notation means OR, and the output of a gate can only be 0 or 1.
Correct: With gates, (OR). The value 2 only appears when you add binary numbers, and then it is written as with a carry digit.
Treating NAND as NOT A AND NOT B, that is
Why it's wrong: NAND flips the output of AND, not the inputs. For , : NAND gives , but .
Correct: NAND : first AND, then NOT. The bar covers the whole product.
Feeding the original inputs into the last gate of a circuit
Why it's wrong: In a circuit each gate only receives the wires connected to it. The last gate usually gets the outputs of earlier gates, not A, B and C.
Correct: Work from the inputs to the output, write the output of every gate next to it, and use those values for the next gate.
Interactive Visual
Truth Table
| A | B | A ∧ B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
1= True0= False
Interactive Sandbox
Expression Calculator
Try these:
History
No calculations yet
Practice Problems
18 problemsWhich gate gives output 1 only when both inputs are 1?
Why It Matters
- Computer chips: a processor contains billions of transistors wired together as gates, and everything it does (adding, comparing, storing) comes down to AND, OR and NOT on 1s and 0s
- Adding numbers: two gates, an XOR and an AND, are enough to add two binary digits, and chains of such circuits add whole numbers
- Alarms and safety systems: an alarm rings when it is armed AND a door OR a window is open
- Cars and machines: a seat belt warning lights up when the engine is on AND the belt is NOT fastened; a press only works when both hands push two buttons (AND)
- Lights at home: a light that can be switched from two places (stairs, hallway) is an XOR circuit
Real World Applications
Alarm Systems
A home alarm is a small logic circuit: sensors give 1 or 0, gates decide whether the siren gets 1.
Example:
With armed switch , door sensor and window sensor , the alarm rings when .
An alarm uses : when the system is armed, when the door is open, when the window is open.
In how many of all possible input combinations does the alarm ring?
Step 1: Write the mathematical expression
Write the number of input combinations as a power of 2:
Adding Numbers in a Chip
Every addition a computer does is built from half adders and full adders made of gates.
Example:
A half adder computes the sum digit and the carry digit of two binary digits.
A half adder gets the inputs and . It outputs and , and the result is read as the binary number .
What are S and C, and which ordinary number does the result stand for?
Step 1: Write the mathematical expression
Write the addition the circuit performs:
Building Chips from NAND Gates
Chip makers like NAND gates because every other gate can be built from NAND gates alone.
Example:
Connect both inputs of a NAND gate to the same signal : the output is , so it works as a NOT gate.
A small chip package holds 4 NAND gates. A NOT gate needs 1 NAND gate, and an AND gate needs 2 (a NAND followed by a NAND used as NOT). A designer needs 3 AND gates and 2 NOT gates.
How many NAND gates and how many chip packages does the designer need?
Step 1: Write the mathematical expression
Write the number of NAND gates as one calculation:
Key Takeaways
- 1A logic gate takes inputs that are 1 (voltage on) or 0 (voltage off) and gives one output, also 1 or 0
- 2AND gives 1 only when both inputs are 1; OR gives 1 when at least one input is 1; NOT flips its single input
- 3XOR gives 1 when the inputs are different; NAND and NOR are the opposites of AND and OR
- 4Gate notation: (AND), (OR), (NOT), (XOR), and here
- 5To find the output of a circuit, go from the inputs to the output and write down the output of every gate
- 6Name each gate's output as an expression to get the Boolean expression of the whole circuit
Frequently Asked Questions
Glossary
- Logic gate
- An electronic circuit that performs one Boolean operation on inputs of 1 and 0
- Input / output
- The signals going into a gate and the single signal coming out of it
- Circuit
- Gates connected by wires, where the output of one gate is an input of another
- Inverter
- Another name for the NOT gate, which flips 1 to 0 and 0 to 1
- XOR (exclusive OR)
- A gate whose output is 1 when its inputs are different, written
- Half adder
- A circuit of one XOR and one AND gate that adds two binary digits: ,
Formula Card
AND
1 only when both inputs are 1
OR
1 when at least one input is 1
NOT
Flips the input
XOR
1 when the inputs are different
NAND
Opposite of AND: 0 only when both inputs are 1
NOR
Opposite of OR: 1 only when both inputs are 0