Sources and Logic Gates: Where Computation Begins
Before Logic: You Need a Reference
Before we can use transistors to make logic, we need a source of energy: without electricity, logic gates will not work.
A digital 1 and 0 are not abstract numbers. They are voltage ranges measured relative to a reference point (ground). The power supply provides the potential difference that makes this distinction physically possible.
Normally computers CPU's work at 5V, 3.3V, or even lower voltages (for various reasons that out of scope for this article).
Transistors: Physical Switches
Since now our computer has a source of energy, next we need to put transistors inside. Transistors are basically solid state switches, made of silicon.
And if we arrange the transistors in a certain way we can create logic gates.
(If you want to know how we came up with logic gates you can read this article).
They are called gates because they literally behave like that. They only allow to pass the electricity if certain criteria is being met. Logic gates are an implementation of Boolean algebra.
We have logic gates with 1 or 2 inputs. But both of them has a single output. Adding more inputs doesn't give more types of gates, it only adds more inputs, no more functionality.
One-Input Gates: Inversion and Signal Integrity
With one input gates, there's only 2 types of them:
- NOT gate (also called inverter)
- BUFFER gate (also called amplifier)
The NOT gate, it's purpose is to output an inverted signal that input is. If the Input is 1, the Output is 0, and vice versa.
Note: All the tables shown here are a list of all possible combinations. This is also called Truth Table.
| Input | Output |
|---|---|
| 0 | 1 |
| 1 | 0 |
The BUFFER gate, it's purpose is to repeat on the output what is in the input.
It's an repeater, or better described as an amplifier. Yes digital circuits, sometimes the signal needs to be amplified, because of various reasons, one of them is distance. Distance weakens the signal. And if the signal reaches the destination logic gate, it can reach weak enough, that it can't trigger the transistor.
Remember: Transistors work with a clear signal, they have a certain voltage threshold, to trigger the open/closed position. In terms of logic the BUFFER gate is not useful, but they are essential for restoring the signal strength, ensuring the destination receives a clear signal to distinguish which state are they transmitting.
| Input | Output |
|---|---|
| 0 | 0 |
| 1 | 1 |
Two-Input Gates: Relationships
Here is where the "magic" happen. Why? When you have 2 inputs you can make computers possible. You need at least 2 independent signals. This enables you to take decisions.
With 2 inputs there are 16 possible logic gates, but not all of them are useful for building logic for a computer.
The most easy to understand are the AND, OR gates.
The AND gate it's output is 1 when only both inputs are also 1. In other input conditions, the output is 0.
The OR gate it's output is 1, when at least one input is 1.
| Input A | Input B | Output |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 1 | 1 |
| Input A | Input B | Output |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 1 | 1 |
Another logic gate with 2 inputs are the XOR gate (Exclusive OR gate). It's output is 1 only if one of the inputs is exclusively 1.
| Input A | Input B | Output |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 1 | 0 |
There's also available the XNOR gate which is a XOR gate with a NOT gate. So the inverted result of an XOR gate is: the output is 1 when both inputs are the same.
| Input A | Input B | Output |
|---|---|---|
| 0 | 0 | 1 |
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 1 | 1 |
Universal gates
There's another 2 logic gates, but those ones are special. Why? Because they are universal. Universal in a sense that if you have only this type of logic gate, with them you can make any other type of logic gates.
The NAND gate and NOR gate if you arrange those logic gates in a certain way you can make them to have the functionality of other types of logic gates. Why this is useful? Mainly for manufacturing, and cost. If a factory only need to manufacture 1 type of logic gate, it will be easier and cheaper to make.
The NAND gate is when you add an NOT gate to an AND gate. A function of an NOT gate is to invert the signal. So you can guess in what conditions it's output is 1. In a AND gate it's output is 1 only when both of it's inputs are 1. In a NAND gate it's the opposite, it's output is 0 only when both inputs are 1.
| Input A | Input B | Output |
|---|---|---|
| 0 | 0 | 1 |
| 1 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 1 | 0 |
The NOR gate is also the same as a OR gate but you add a NOT gate. So it's output is only 1 when both inputs are 0.
| Input A | Input B | Output |
|---|---|---|
| 0 | 0 | 1 |
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 1 | 0 |
But, the real power of logic gates it's the combination with them, connecting the outputs to the inputs of other logic gates. It's cascading effect is what makes logic gates so useful, enabling to do more complex operations. In this article will show what you can build by connecting this logic gates. (Coming Soon)