Computer science
Truth table of a Boolean expression
Write the expression in whichever notation you prefer — AND/OR/NOT, the symbols · + ', or && || ! — and get the complete truth table.
How to read a truth table
A truth table lists every possible combination of the inputs and the value the expression takes in each. With n variables there are 2ⁿ rows: two variables give four, three give eight, four give sixteen. The conventional order is that of a binary counter, with the first variable changing slowest, and it exists to guarantee no combination is skipped.
The three basic operators reduce to three sentences. AND is true only when both inputs are, OR is false only when both are false, NOT flips. XOR, less used in early exercises but central to arithmetic circuits, is true when the inputs differ: it is binary addition without the carry.
The table is also the tool for proving an identity. Two expressions are equivalent when their output columns match row for row, and that is how De Morgan's laws are checked: the negation of an AND is the OR of the negations, and vice versa. It is the transformation that allows any circuit to be built from a single kind of gate.
Common mistakes
- Getting the operator precedence wrong: NOT binds tighter than AND, which binds tighter than OR. Without brackets, A OR B AND C means A OR (B AND C), not (A OR B) AND C.
- Applying De Morgan's law while negating only one term: the negation of (A AND B) is (NOT A) OR (NOT B), with the middle operator changing too.
- Skipping combinations in the table: three variables mean eight rows and all of them have to be listed, even the ones that look obvious. Following binary order is how none gets lost.
Frequently asked questions
How many rows does a truth table have?
Two to the power of the number of variables: 2ⁿ. Two variables give four rows, three give eight, four give sixteen. Each row is a different combination of zeros and ones.
What is the precedence of Boolean operators?
NOT first, then AND, then XOR, then OR. It is the same hierarchy as ordinary algebra if you think of AND as multiplication and OR as addition, which is why they are written · and +.
What do De Morgan's laws say?
That the negation of a conjunction is the disjunction of the negations, and vice versa: NOT(A AND B) = NOT A OR NOT B, and NOT(A OR B) = NOT A AND NOT B. They are checked by comparing the output columns.
What is the difference between OR and XOR?
OR is true even when both inputs are true; XOR is not. XOR is true only when the inputs differ from each other, which is why it is also called exclusive OR.
How this calculation works
Operators: NOT A is 1 when A is 0. A AND B is 1 only if A = B = 1. A OR B is 0 only if A = B = 0. A XOR B is 1 when A ≠ B. Precedence, strongest first: NOT, AND, XOR, OR; brackets override it. Rows with n variables: 2ⁿ. De Morgan's laws: ¬(A·B) = ¬A + ¬B and ¬(A + B) = ¬A · ¬B. Useful identities: A + A·B = A (absorption), A·(A + B) = A, A + ¬A = 1 (excluded middle), A·¬A = 0 (non-contradiction). The parser accepts word notation, symbolic notation (· + ') and programming operators (&& || !).