Boolean logic deals with values that can only be TRUE or FALSE (1 or 0). It forms the foundation of all digital circuits and computers. All computer decisions are ultimately made using combinations of AND, OR, and NOT operations.
A NOT gate takes ONE input and outputs the OPPOSITE. If the input is 1 (TRUE), the output is 0 (FALSE), and vice versa.
| Input A | NOT A (Output) |
|---|---|
| 0 | 1 |
| 1 | 0 |
An AND gate takes TWO (or more) inputs and outputs 1 ONLY if ALL inputs are 1. Think of it as: "both must be true".
| Input A | Input B | A AND B (Output) |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
An OR gate takes TWO (or more) inputs and outputs 1 if AT LEAST ONE input is 1. Think of it as: "at least one must be true".
| Input A | Input B | A OR B (Output) |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Real circuits combine multiple gates. The output of one gate can feed into another.
A NAND gate is an AND gate followed by a NOT. Output is 0 ONLY when both inputs are 1.
| A | B | A AND B | NOT(A AND B) |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 0 |
A NOR gate is an OR gate followed by a NOT. Output is 1 ONLY when both inputs are 0.
| A | B | A OR B | NOT(A OR B) |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 |
The same AND, OR, NOT operators used in logic gates are used in pseudocode conditions:
IF age >= 18 AND hasID = TRUE THEN
OUTPUT "Entry allowed"
ENDIF
IF score > 100 OR score < 0 THEN
OUTPUT "Invalid score"
ENDIF
IF NOT memberLoggedIn THEN
OUTPUT "Please log in"
ENDIF
4 questions · 9 marks
| Term | Definition |
|---|
10 minutes · mixed marks