Boolean Logic: Logic Gates
Boolean Logic: Logic Gates
Logical connectives: they aren't just for truth tables anymore. You can actually use them in the computer. If you have no idea what we're talking about, head back to Science Topic 1 to refresh your knowledge.
You can make circuit-based logic gates, which are ways for controlling the flow of electricity in a—you guessed it—circuit.
These logic gates take in input and give an output, just like the connectives they're named after. What goes on in the gate, though, is shrouded in mystery. It's just a black box where all we know is the basic function.
An Or Gate splits in half, with a logical gate on either side. Then, as long as one gate's closed (or True), electricity will get from one end of the gate to the other end no problem.
Boom. Logic
The And Gate also has one output from two inputs, but the two logic gates are one after another, meaning that both need to be closed (a.k.a. True) in order for electricity to run from one end to the other.
The Xor Gate (or the Exclusive Or Gate) gets much more complicated, but it can be simplified down to (A ∨ B) ∧ (~A ∨ ~B). Yeah. It's a sticky diagram.
The Not Gate is the only one that takes in one input to produce one output (which is…the opposite of the input). True becomes False and False becomes True.
If you want to take the or of three separate values, all you need to do is take the or of two of them, then take the or of that output with the third value. As long as one of them's true, it'll all come out true (just like in the logic table).
Just like you can take the negation of an input, you can also take the negation of an And and Or Gate. Those are called Nand and Nor.
Now let’s say you're the head engineer at the De Morgan Logic Gate factory and, because of recent cost cutting initiatives, found out that you could only produce one kind of logic gate: Nand gates. You can still create all the other gates, you'll just need to get creative.
In fact, any other logic gate can be made with Nand or Nor Gates alone—as long as you have them in the right order and pairings. For this reason, Nand and Nor are called universal gates.
Here are a couple of ways to do it so that you can still make all the basic gates.
To make a Not Gate, just take the Nand of something and itself ~(X ∧ X). Since X ∧ X will always be True if X is True (we hope), the negation's going to return False. If X is False, X ∧ X will also be False, so its negation will be True.
To make an And gate, take the Nand of two things twice. Just like in outdated grammar classes, a double negative makes a positive, so both negations are going to cancel each other out. All that's left will be And.
The Or Gate gets more complicated. If the values are A and B, you'd need to
- Nand A and B with themselves to negate them (just like in the Not Gate).
- take the Nand of A and B's negations—a.k.a. ~(~A ∧ ~B).
After that tangle of gates, you'll get True if A or B is True (or both) and False if A and B are both False.
It can get more complicated.
Creating an Xor Gate is…fun. Take heart, Shmooper: it only takes five gates to get there.
Think you're ready to try your hand at some logic gates? Check out MIT's gate-builder to power pixel lightbulbs.
Remember: always practice safe logic.