Boolean Logic
Youtube
The above terms are synonymous, in that they all refer to the same thing: boolean values. Earlier computers did not always use binary, it took decades of iteration to settle on binary because of its simplicity and efficiency.
Above are 3 common boolean operations, AND, NOT, OR and their truth tables, which show all possible inputs and outputs of each operation. The inputs are electrical signals that are either high or low voltage, which we represent as 1 and 0 respectively.
Boolean operations re-use symbols from math such as addition and multiplication + *, and work almost the same. The important thing you have to watch out for is the case of 1 +(or) 1. It’s not 2! Because we are working with binary values, not regular numbers! So use the truth table or speak out loud and read + as OR to resist your natural math instincts.
Let’s evaluate some boolean expressions:
Given 3 binary inputs, there can only be 8 possible combinations, so we can write a table for every possible input, and evaluate the function to get the output(the last row).
Going from:
Boolean function → truth table is pretty straight forward, we just plug in values and evaluate the boolean expression.
BUT
Truth table → Boolean function is a little more tricky.
You’ll be given a truth table, and you’re going to need to find the right combination of operations to write the boolean function that produces the truth table. Let’s explore why and how to do this with an example.
#Truth Table to Boolean Function
| Mush | Pep | OUT |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Say you’re throwing a party, and you only want pizzas that have both mushrooms
AND pepperoni, OR ones that only mushrooms, OR ones that are plain with no toppings. Above is the truth table for this scenario.
To find the combination of operations that will allow the pizzas you want to pass, while rejecting ones you don’t want, all you have to do is:
This perfectly implements our truth table that filters out pizzas that we don’t want.
By cleverly combining and arranging these simple logic gates, we can create complex behavior. Everything you do on a computer from games, shopping, browsing the web, etc, all boils down to clever manipulations of 0’s and 1’s using these basic operations.
Try to come up with your own truth table and see if you can implement it with logic gates. Here are a few example problems: