Boolean logic
AND, OR, NOT, XOR
Goal: Fill truth tables for the basic operators · 9 min
Boolean logic works with only two values: true (1) and false (0). Four operators build everything:
| A | B | A AND B | A OR B | A XOR B | NOT A |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 |
- AND: true only if both are true.
- OR: true if at least one is true (also both!).
- XOR (exclusive or): true if exactly one is true.
- NOT: flips the value.
In code: AND = &&, OR = ||, NOT = ! (JavaScript); and, or, not (Python). In hardware these are logic gates built from transistors.
Worked example: A door alarm
- Alarm if the system is armed AND (door open OR window open).
- Armed = 1, door = 0, window = 1 → 0 OR 1 = 1.
- 1 AND 1 = 1 → the alarm sounds.