Intro to Computer Science / Unit 5: Conditionals and Boolean Logic
5.4 Truth Tables
Notes
A truth table lists every combination of inputs and the result.
| A | B | A and B | A or B |
|---|---|---|---|
| True | True | True | True |
| True | False | False | True |
| False | True | False | True |
| False | False | False | False |
not Ais the opposite of A.- De Morgan's laws:
not (A and B)equals(not A) or (not B), andnot (A or B)equals(not A) and (not B). - With 2 inputs there are 4 rows; with 3 inputs there are 8 rows (2 to the power of the number of inputs).
Practice
For which input does
A or B give False?or is False only when both inputs are False.
How many rows does a truth table for three inputs A, B and C have?
Each input has 2 values, so 2 x 2 x 2 = 8 rows.
Which expression is equivalent to
not (x > 5 and y > 5)?De Morgan's law: negating an and flips it to or and negates each part. The opposite of > is <=.
Ready for more? Take the Unit 5 test.