Truth Tables and Logical Operators
Logic in Computing
Every decision a computer makes — whether to grant access, whether a value is in range, whether to send a notification — is ultimately a logical operation. The three fundamental logical operators are AND, OR and NOT. A truth table is the tool used to show exactly what output a logical expression produces for every possible combination of inputs. Your specification requires you to construct truth tables for expressions using AND, OR and NOT with up to three inputs.
There are only three operators to know: AND returns True only when both inputs are True. OR returns True when at least one input is True. NOT flips a single input — True becomes False and False becomes True.
AND — Both Must Be True
The AND operator requires every input to be True before the output is True. In real systems: a bank transfer is authorised only if the user is authenticated AND the account has sufficient funds. Both conditions must hold.
Truth table for AND with two inputs A and B:
A = False, B = False → Output = False
A = False, B = True → Output = False
A = True, B = False → Output = False
A = True, B = True → Output = True
Only the last row gives True. “All or nothing.”
OR — At Least One Must Be True
The OR operator returns True when at least one input is True. In real systems: a security alarm triggers if a door sensor is activated OR a motion sensor is activated. Either one is enough.
Truth table for OR with two inputs A and B:
A = False, B = False → Output = False
A = False, B = True → Output = True
A = True, B = False → Output = True
A = True, B = True → Output = True
Only the first row (both False) gives False. “Anything works.”
NOT — Flip the Input
The NOT operator takes a single input and reverses it. In real systems: a smart light turns on if NOT(daylight) — meaning it is on only when daylight is False (i.e. it is dark).
Truth table for NOT with input A:
A = False → NOT A = True
A = True → NOT A = False
The number of rows in a truth table is 2 raised to the power of the number of inputs. Two inputs: 22 = 4 rows. Three inputs: 23 = 8 rows. Always work through the rows systematically — a consistent pattern (e.g. alternating True/False for the last column, then pairs for the second, then groups of four for the first) ensures you never miss a combination.
Expression: A AND (NOT B). This combines NOT with AND — first apply NOT to B, then AND the result with A.
Step 1: List all combinations of A and B (4 rows for 2 inputs). Use a systematic pattern — last column alternates T/F; first column alternates in pairs:
Row 1: A=False, B=False
Row 2: A=False, B=True
Row 3: A=True, B=False
Row 4: A=True, B=True
Step 2: Add a column for NOT B (flip B in each row):
Row 1: NOT B = True
Row 2: NOT B = False
Row 3: NOT B = True
Row 4: NOT B = False
Step 3: Apply AND to A and NOT B:
Row 1: False AND True = False
Row 2: False AND False = False
Row 3: True AND True = True
Row 4: True AND False = False
The expression is True only in row 3 — when A is True and B is False. Reading this as a real decision: “the feature is active only if option A is enabled AND option B is disabled.”
Three-Input Truth Tables
When an expression has three inputs (A, B and C), there are 23 = 8 possible combinations. The approach is exactly the same: list all 8 rows systematically, then evaluate any intermediate expressions column by column before arriving at the final output.
Example expression: (A AND B) OR (NOT C). To evaluate this, you need three columns: one for A AND B, one for NOT C, and one for the whole expression using OR.
All 8 rows with systematic input listing (C alternates T/F every row; B alternates every two rows; A alternates every four rows):
Row 1: A=F, B=F, C=F → A AND B = F; NOT C = T; F OR T = True
Row 2: A=F, B=F, C=T → A AND B = F; NOT C = F; F OR F = False
Row 3: A=F, B=T, C=F → A AND B = F; NOT C = T; F OR T = True
Row 4: A=F, B=T, C=T → A AND B = F; NOT C = F; F OR F = False
Row 5: A=T, B=F, C=F → A AND B = F; NOT C = T; F OR T = True
Row 6: A=T, B=F, C=T → A AND B = F; NOT C = F; F OR F = False
Row 7: A=T, B=T, C=F → A AND B = T; NOT C = T; T OR T = True
Row 8: A=T, B=T, C=T → A AND B = T; NOT C = F; T OR F = True
The output is True in five of the eight rows: rows 1, 3, 5, 7, and 8. Notice that whenever C is False, NOT C is True, making the OR output True regardless of A and B. The output is only False when A AND B is False and C is True.
Using Logic to Solve Real Problems
Truth tables are not just exam exercises — they describe the Boolean logic that controls real systems. An e-commerce checkout might use: (item in stock AND payment verified) OR (pre-order enabled). A content filter might use: NOT(verified age) AND content is restricted. Constructing the truth table for any such expression tells you exactly when the output will be True, allowing a programmer to verify the logic before writing a single line of code.