A logic gate is a circuit that implements a Boolean operation on one or more inputs to produce a single output. They are the basic building blocks with which we construct digital decision, control, and computation.
A microprocessor may seem very complex, but if we zoom in, we will see millions of transistors organized into logical structures. A computer is not “smart”; it executes a huge number of simple operations.
To describe their behavior, we use the truth table, a list that tells us: “for each possible combination of inputs, this is the output you will get”.
Let’s look at the four magnificent ones you need to master.
The NOT Gate (the Inverter)
It is the simplest one. It has a single input and a single output. Its function is to contradict: it inverts the logical state.
- If a
1(HIGH) enters → a0(LOW) comes out. - If a
0(LOW) enters → a1(HIGH) comes out.
Symbol: A triangle with a small circle at the tip (the circle always denotes inversion).
Truth Table
| Input (A) | Output (Y) |
|---|---|
| 0 | 1 |
| 1 | 0 |
Practical use: It is used to generate the complement of a signal. For example, if you have a chip that is activated with a low level (active low) but your control signal is positive, you put a NOT gate in between.
The AND Gate (the Strict One)
The AND gate has two (or more) inputs and one output.
The output will be 1 ONLY if ALL inputs are 1.
Imagine the security of a nuclear silo. To launch the missile, the general AND the president must turn their keys at the same time. If only one does it, nothing happens.
Electrical analogy: Two switches in series. The bulb only lights if you close the first one and the second one.
Truth Table
| Input A | Input B | Output ( |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Mathematically it is equivalent to a binary multiplication.
The OR Gate (the Flexible One)
The OR gate outputs a 1 if AT LEAST ONE of its inputs is 1.
It only outputs a 0 if all inputs are off.
Imagine a doorbell with a front door and a back door. The bell should ring if someone presses the front button OR if someone presses the back button (or both).
Electrical analogy: Two switches in parallel. The bulb lights if you close one, the other, or both.
Truth Table
| Input A | Input B | Output (A + B) |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Mathematically it is equivalent to a logical addition (although careful,
The XOR Gate (the Exclusive One)
This one is the favorite of computer scientists. XOR stands for exclusive OR. It resembles the OR gate, but with a key difference: “Either one or the other, BUT NOT BOTH.”
The output is 1 only if the inputs are different.
If both are 0 or both are 1, the output turns off.
Everyday use: The two-way light switches in a hallway. You can turn it on from one end and off from the other. If both switches are in the same position, the light is off. If they are in different positions, the light is on.
Truth Table
| Input A | Input B | Output ( |
|---|---|---|
| 0 | 0 | 0 (Same) |
| 0 | 1 | 1 (Different) |
| 1 | 0 | 1 (Different) |
| 1 | 1 | 0 (Same) |
XOR in binary addition: it gives us the result bit of a one-bit addition without input carry.
1 + 1 in binary is 10 (output 0 and carry 1).
The XOR gate gives us the result 0, and an AND gate gives us the carry 1. By combining XOR and AND gates, ALUs (Arithmetic Logic Units) that add numbers in the CPU are built.
Real Chips: The 7400 Series
Although nowadays all of this lives inside microcontrollers, you can still buy classic (DIP) chips that contain these gates to use on breadboards:
- 74HC04: Contains 6 NOT gates.
- 74HC08: Contains 4 AND gates.
- 74HC32: Contains 4 OR gates.
- 74HC86: Contains 4 XOR gates.
| Gate | Logic | Question to the circuit | Mathematical Symbol |
|---|---|---|---|
| NOT | Inversion | “The opposite?” | |
| AND | All or nothing | “Are ALL activated?” | |
| OR | Any | “Is ANY activated?” | |
| XOR | Difference | “Are they DIFFERENT?” |
With these four basic pieces we can build anything, from a simple alarm system to the processor of an iPhone. We just need to connect many of them.