Menu

Truth tables

Boolean Operator Precedence

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.

The order to follow

PriorityOperatorWhat it does
1BracketsWork out whatever is inside them before anything outside them
2NOTInverts a single input, or the result of a bracketed expression
3ANDGives 1 only when both of its inputs are 1
4ORGives 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 worked example

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.

Two expression trees. F AND NOT R OR H works NOT R first, then AND, then OR, giving 0 when F=1, R=1 and H=0. NOT (F AND R) works the bracketed AND first and then inverts the result.

Practise this