Basic Logic Gates
A logic gate takes one or more binary inputs and produces a single binary output (0 or 1). The three basic gates are:
- AND gate — the output is 1 only when all inputs are 1.
- OR gate — the output is 1 when any input is 1.
- NOT gate — inverts the input; 0 becomes 1 and 1 becomes 0.
Key idea
Remember the difference between AND and OR: AND needs ALL inputs to be 1 to give 1, while OR only needs ONE input to be 1.
Combination Gates
Several other gates are built from the basic gates:
- NAND gate — the inverse of AND; the output is 0 only when all inputs are 1.
- NOR gate — the inverse of OR; the output is 1 only when all inputs are 0.
- XOR gate (exclusive OR) — the output is 1 when the inputs are different, and 0 when the inputs are the same.
Truth Tables
A truth table lists every possible combination of inputs and the resulting output of a gate. The table below compares the AND, OR and XOR gates for two inputs A and B:
| A | B | A AND B | A OR B | A XOR B |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 |
Example
An alarm sounds only when the door is open AND the alarm switch is on. This is an AND gate: both conditions must be true (1) before the output (alarm) becomes 1.
Remember
AND = all 1; OR = any 1; NOT = invert; XOR = different inputs give 1. Combination circuits can be formed by connecting several basic gates together.