Boolean logic & truth tables (CS framing)
Computer Science · Foundations
Question 1 of 10
0How many input combinations does a function of four Boolean inputs have?
Stuck? Read the explanation
Unlocks at a streak of 5 correct answers in a row.
Embed this practice on your site or class page
Paste this HTML into your page. Students practise right there; it is free and needs no account.
Boolean logic & truth tables (CS framing) explained
Boolean logic deals with values that are either true or false, usually written as 1 and 0. Three basic operators combine them. AND gives true only when both inputs are true. OR gives true when at least one input is true. NOT reverses its single input.
A truth table lists every combination of inputs and the output for each one. With n inputs there are rows, so two inputs give 4 rows and three inputs give 8 rows.
In logic, OR is inclusive: true OR true is true. Everyday English "or", such as on a menu, often means one or the other but not both, so the two meanings can differ.
A common mistake is to use the everyday meaning of "or" in a truth table, recording true OR true as false. Use brackets to show the order of operations, because many people forget that NOT is applied before AND, and AND before OR.
Worked example
Complete the truth table for (A AND B) OR NOT C and count the rows that give 1:
A B C output
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
For example, the row 0 0 0 gives (0 AND 0) OR NOT 0, which is 0 OR 1, or 1. There are 8 rows, and the output is 1 in 5 of them.
Key facts
- Precedence: NOT first, then AND, then OR. Brackets override this. means .
- XOR (exclusive OR) is true when exactly one input is true. It differs from OR only on the row where both inputs are true.
- NAND is NOT(AND). NOR is NOT(OR).
- De Morgan's laws: NOT(A AND B) = (NOT A) OR (NOT B), and NOT(A OR B) = (NOT A) AND (NOT B).
- Two expressions are equivalent when their truth tables have the same output on every row.
Worked example 2
Show that NOT(A AND B) is equivalent to (NOT A) OR (NOT B). Add a column for each part of the expression.
A B A AND B NOT(A AND B) NOT A NOT B (NOT A) OR (NOT B)
0 0 0 1 1 1 1
0 1 0 1 1 0 1
1 0 0 1 0 1 1
1 1 1 0 0 0 0
The two result columns, NOT(A AND B) and (NOT A) OR (NOT B), match on all 4 rows: 1, 1, 1, 0. So the expressions are equivalent. This is De Morgan's law, and it is what makes a NAND gate and an "either input off" circuit the same thing.
Worked example 3
A greenhouse fan switches on when the temperature is high (H) OR the humidity is high (U), but it must never run when the cover is closed (C). Write the expression, complete the truth table, and count the rows where the fan is on.
-
Expression: .
-
Work out the bracket first, then NOT C, then combine them.
H U C H OR U NOT C fan 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 1 1 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 0 0 -
Three inputs give rows.
-
The fan is on in 3 of the 8 rows.
Check: the fan can only be on when C = 0. That leaves 4 rows, and in one of those (H = 0, U = 0) the bracket is false, so .
Common mistakes
- Using the everyday "or". In logic, 1 OR 1 is 1. Only XOR gives 0 there.
- Ignoring precedence. with , , is . Reading it left to right as would give 0.
- Misapplying De Morgan. NOT(A AND B) is not (NOT A) AND (NOT B). The AND must change to OR when the NOT goes inside the bracket.
- Missing rows. Count in binary (000, 001, 010, ...) so that all combinations appear once.
- Skipping the working columns. One column per sub-expression stops slips on long expressions.
Exam tips
- List the inputs in binary counting order. It is quick to check and it never misses a row.
- For a word problem, underline the words AND, OR, NOT, "but" and "unless" before you write the expression. "But never" means AND NOT.
- To prove equivalence, show both columns and say "same output on every row".
- When you count the true rows, count them again after you finish the table.
- The bitwise operators work the same way, one bit at a time: 1100 AND 1010 = 1000, 1100 OR 1010 = 1110, and 1100 XOR 1010 = 0110.
What you will practise
105 multiple-choice questions (Easy, Medium, Hard). Each answer is followed by an explanation.
Example questions
- True AND True is:
- True OR False is:
- NOT True is:
- False AND anything is:
- NOT (A AND B) is equivalent to:
- NAND (NOT AND) of True and True is:
- False OR False is:
- XOR (exclusive OR) of True and True is:
…and 97 more.