Truth tables
When a Boolean expression contains more than one operator, it is not worked out from left to right. A fixed order called operator precedence decides which part is applied first, so the expression always keeps one clear meaning.
| Priority | Operator | What it does |
|---|---|---|
| 1 | Brackets | Work out whatever is inside them before anything outside them |
| 2 | NOT | Inverts a single input, or the result of a bracketed expression |
| 3 | AND | Gives 1 only when both of its inputs are 1 |
| 4 | OR | Gives 1 when at least one of its inputs is 1 |
Brackets override the normal order, so a bracketed OR is settled before an AND sitting outside it. Logical expressions are written with the words AND, OR and NOT in capitals, and parentheses show clearly which parts are grouped together.
A club meets when F (field free) AND NOT R (raining) OR H (hall booked). NOT is applied before AND, and AND before OR, so the expression really means (F AND (NOT R)) OR H. With F = 1, R = 1 and H = 0: NOT R is 0, F AND 0 is 0, and 0 OR H is 0, so the club does not meet.
Putting NOT in front of brackets works differently. To evaluate NOT (F AND R), work out F AND R first and then invert that single result: if F AND R came to 1 then NOT (F AND R) is 0, and if it came to 0 the answer is 1. This is not the same as (NOT F) AND R, which inverts only F before the AND is applied.
Edexcel GCSE Computer Science · Truth tables
Edexcel GCSE Computer Science · Logical Operators