LearnTronics
AND, OR, NOT — Logic in Ordinary Language
Four little words do a lot of work
Much of digital logic grows from a few ideas we already use in speech: AND, OR, NOT, and the special “one but not both” form called XOR.
AND
“The motor may run when the guard is closed AND the start command is present.” Both conditions must be true.
| A | B | A AND B |
|---|---|---|
| F | F | F |
| F | T | F |
| T | F | F |
| T | T | T |
OR — the word that causes trouble
In everyday English, “or” can mean two different things.
“Joe stopped for gas or a meal” may still be true if Joe did both. That is inclusive OR.
“Turn left or right” usually means one direction but not both. That is exclusive OR, written XOR.
| A | B | A OR B |
|---|---|---|
| F | F | F |
| F | T | T |
| T | F | T |
| T | T | T |
| A | B | A XOR B |
|---|---|---|
| F | F | F |
| F | T | T |
| T | F | T |
| T | T | F |
NOT
NOT simply reverses a truth value. If A means “the door is open,” then NOT A means “the door is not open.”
| A | NOT A |
|---|---|
| F | T |
| T | F |
Some terminology
AND is called conjunction. OR is disjunction. XOR is exclusive disjunction. NOT is negation. Collectively we can simply call them logical operators or connectives.
Truth tables
The small tables above are examples of a truth table. A truth table lists every possible combination of truth values for its input statements, then shows the resulting truth value of an expression for each combination.
Truth tables are useful because they replace guesswork with a complete check. Instead of asking whether a logical expression seems right, we can test every possible input case.
How to construct a truth table
If there are n variables, the complete truth table needs 2n input rows.
For two variables, A and B, the four combinations are FF, FT, TF, and TT. For three variables there are 8 combinations. Four variables require 16 rows.
Give each intermediate operation its own column. Work from the innermost or simplest operation outward.
Once all intermediate columns are complete, the final column describes the whole logical expression.
| Variables | Number of input rows |
|---|---|
| 1 | 2 |
| 2 | 4 |
| 3 | 8 |
| 4 | 16 |
| 5 | 32 |
The number of rows doubles each time another independent variable is added because every existing combination must be considered once with the new variable false and once with it true.
Two variables can describe 16 different functions
For A and B, the input order below is always:
Each possible function assigns either F or T to each of those four rows. Four output positions, each with two choices, gives 24 = 16 possible output patterns.
| # | Output pattern FF FT TF TT | Function / meaning |
|---|---|---|
| 0 | F F F F | Always false — contradiction / constant 0 |
| 1 | F F F T | A AND B |
| 2 | F F T F | A AND NOT B |
| 3 | F F T T | A — output simply follows A |
| 4 | F T F F | NOT A AND B |
| 5 | F T F T | B — output simply follows B |
| 6 | F T T F | A XOR B |
| 7 | F T T T | A OR B |
| 8 | T F F F | A NOR B — NOT (A OR B) |
| 9 | T F F T | A XNOR B — A and B have the same truth value |
| 10 | T F T F | NOT B |
| 11 | T F T T | B implies A — B → A |
| 12 | T T F F | NOT A |
| 13 | T T F T | A implies B — A → B |
| 14 | T T T F | A NAND B — NOT (A AND B) |
| 15 | T T T T | Always true — tautology / constant 1 |
AND, OR, XOR, NAND, NOR and XNOR are the names most often encountered in electronics, but mathematically they are only some of the sixteen possible ways two Boolean inputs can determine one Boolean output.
Example: implication is also a two-variable function
Suppose A means “the start button is pressed” and B means “the motor is allowed to run.” The statement “If A, then B” is written A → B.
| A | B | A → B | Why? |
|---|---|---|---|
| F | F | T | A made no promise because A did not occur. |
| F | T | T | A did not occur, so the implication is not broken. |
| T | F | F | This is the one case that breaks “If A, then B.” |
| T | T | T | A occurred and B followed. |
Its output pattern is therefore T T F T, one of the sixteen patterns in the table above. The next tutorial will examine “if...then” reasoning more closely.
Three variables: work in stages
Now let:
- A = the guard is closed
- B = the start command is present
- C = the stop condition is present
Suppose the motor-run condition is:
With three variables we need 23 = 8 rows. Rather than trying to evaluate the entire expression mentally, create intermediate columns for A AND B and NOT C.
| A | B | C | A AND B | NOT C | (A AND B) AND NOT C |
|---|---|---|---|---|---|
| F | F | F | F | T | F |
| F | F | T | F | F | F |
| F | T | F | F | T | F |
| F | T | T | F | F | F |
| T | F | F | F | T | F |
| T | F | T | F | F | F |
| T | T | F | T | T | T |
| T | T | T | T | F | F |
The final column shows that the motor may run only when the guard is closed, the start command is present, and the stop condition is absent.
A more complex expression
Truth tables become even more useful when several operations are nested. Consider:
With four variables, a complete table would contain 16 input rows. We do not need to solve the whole expression in one jump. Make one column for each step:
2. NOT C
3. NOT C OR D
4. (A OR B) AND (NOT C OR D)
For one sample row, let A = F, B = T, C = T, D = F:
| A | B | C | D | A OR B | NOT C | NOT C OR D | Final |
|---|---|---|---|---|---|---|---|
| F | T | T | F | T | F | F | F |
That same sequence is repeated for the other fifteen input combinations. Intermediate columns are not wasted work: they make it possible to see exactly where a result came from and greatly reduce mistakes.
Why language comes first
The old truth-table page made a particularly useful distinction between the two everyday meanings of “or.” That is exactly the kind of language habit that later determines whether a circuit does what its designer intended.