AND, OR, NOT: combining conditions
A lift should move only if the doors are closed AND someone pressed a button. What happens if an engineer types OR by mistake?
About 30 min · 3 goals · Checked by automated tests; not yet reviewed by an educator
1.Why should I care?
Real decisions rarely depend on one thing. A rover drives only if the path is clear AND the battery is fine. An alarm sounds if the door opens OR a window breaks. These three little words are also the building blocks of every computer chip.
- ◇ Combine two conditions using AND, OR and NOT.
- ◇ Fill in a truth table for a combined rule.
- ◇ Choose the right combination for a safety rule.
2.Predict
Rule: drive IF path clear AND battery OK. The path is clear but the battery is low. Does it drive?
Guess first. Being wrong here is how the surprise works.
3.Discover
Try an AND gate, then an OR gate, then NOT. Flip the inputs through every combination (off-off, off-on, on-off, on-on) and write down when the output is on.
Explorer 05 — Digital logic
Build answers out of ones and zeros
Every digital chip is built from a handful of simple gates. Flip the inputs to watch signals travel through a circuit, then wire your own gates to meet a target truth table.
- 1 (high)
- 0 (low)
- Unknown
- Inverting output
A single two-input gate. Change its type and watch the truth table change.
Inputs
Gates (1 of 8)
G1 = 0
Add a gate
Outputs
- Gates
- 1
- Depth
- 1
- Longest chain of gates a signal passes through
- Rows
- 4
- 2^2 input combinations
- Check
- —
| Set inputs | A | B | Y |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 1 | 0 | |
| 1 | 0 | 0 | |
| 1 | 1 | 1 |
State
Inputs A = 0, B = 0. Outputs Y = 0.
Inputs A = 0, B = 0. Outputs Y = 0.
How to read this
Signals flow left to right. Circles on the left are the inputs, boxes are gates and squares on the right are outputs. A thick bright wire carries a 1, a thin grey wire carries a 0, and each gate shows the value it outputs. A small circle on a gate's output means it inverts (NOT, NAND, NOR, XNOR).
The truth table lists every possible input combination and what the circuit outputs for each, so it describes the circuit completely. Two circuits with the same truth table are equivalent, however differently they are built. That is why NAND alone can make any other gate. Choose a row to set the inputs to it.
Assumptions & limitations
- Ideal logic: every wire is exactly 0 or 1. Real gates use voltage ranges (for example near 0 V and near 3.3 V or 5 V) and an input between them is undefined.
- Gates switch instantly here. Real gates take nanoseconds each, so a deeper circuit is slower, and outputs can glitch briefly while signals race through different paths.
- Only combinational circuits are allowed: no output may feed back into its own input. Feedback is how memory (latches and flip-flops) works, but it needs timing this model does not simulate, so loops are reported as an error.
- Gates here have one input (NOT) or two inputs. Real chips also have three- and four-input gates, and limits on how many inputs one output can drive (fan-out).
- Gate counts are a simple measure of size; real designs also weigh speed, power and the number of transistors per gate.
Can't use the interactive? Read a description instead
The logic lab can be replaced by these truth tables. AND: off+off → off, off+on → off, on+off → off, on+on → on. OR: off+off → off, off+on → on, on+off → on, on+on → on. NOT: off → on, on → off.
4.Watch
→ Watch for the truth tables for AND and OR, and how NOT flips a value.
Introduces AND, OR, NOT and XOR, the building blocks behind every digital decision a computer makes.
10 min 7 s · captions on YouTube · source
Nothing loads from YouTube until you press play.
5.Understand
AND: everything must be true
A AND B is true only when A is true and B is true. One false makes it false. Use AND when every condition is required: move IF doors closed AND button pressed.
OR: anything will do
A OR B is true when A is true, or B is true, or both. Only false when both are false. Use OR when any one reason is enough: alarm IF door opens OR window breaks.
NOT: flip it
NOT A is true when A is false. It lets you write rules like drive IF NOT obstacle. Combine them: drive IF path clear AND NOT battery low.
Truth tables
With two conditions there are only four possibilities: both false, first only, second only, both true. A truth table lists all four and the result. Checking all four rows is a quick way to make sure a rule does what you mean.
Explain it another way
A theme park ride: you can go on IF you're tall enough AND you have a ticket. You get free entry IF it's your birthday OR you're under 5.
AND, OR and NOT are Boolean operators. With two inputs, AND is true in 1 of 4 rows, OR in 3 of 4. Every digital circuit, from a calculator to a phone, is built from gates that compute these.
Factory machines use 'two-hand controls': the press only moves IF the left button AND the right button are both held. That guarantees both of the operator's hands are well away from the blade.
Worked example 1
Fill in the truth table for 'lift moves IF doors closed AND call pressed'.
Doors closed? / Call pressed? → Moves?
- No / No → No
- No / Yes → No
- Yes / No → No
- Yes / Yes → Yes
Only one row moves. With OR by mistake, the lift would move in three rows, including with the doors open.
Common mix-ups
- OR means one or the other but not both.
✓ In logic, OR is also true when both are true. 'One but not both' is a different operator called XOR. - AND and OR are interchangeable in everyday rules.
✓ They give very different behaviour. For safety, AND usually means 'every condition must be met'.
6.Practice
Practice, not a test. Wrong answers get a hint and another try.
Practice 1
A burglar alarm should sound if the door opens or a window breaks. Which word joins the two conditions?
Practice 2
A paper shredder should run only when the bin is in place and paper is detected. Which rule is right?
Practice 3
In the four-row truth table for A OR B, in how many rows is the result true?
Practice 4
A rover's rule is 'drive IF NOT obstacle'. The obstacle sensor says true. Does it drive?
7.Apply it
Write a combined rule for a plant-watering helper: water IF the soil is dry AND it is NOT already raining. Draw its four-row truth table. Then add a third condition of your own and say whether it joins with AND or OR.
8.Reflect
Concepts: Logic gates and Boolean algebra · Decisions and loops