The Intuition: "One or the Other, But Not Both"
Imagine you're at a restaurant with a friend. The menu has two specials: a burger and a pizza. The waiter asks: "Who wants the burger?" and "Who wants the pizza?" You and your friend can each choose one item, but the restaurant has a rule: you cannot order both specials together (that would be too much food), and you cannot order nothing (you're both hungry).
So the only acceptable situations are:
- You take the burger, your friend takes the pizza.
- You take the pizza, your friend takes the burger.
That's the core idea of exclusive-OR: exactly one of the two things happens, but not both, and not neither.
The Precise Statement
An XOR gate (short for exclusive-OR) is a digital logic gate with two inputs (call them A and B) and one output Y. The output is 1 (true) only when the inputs are different. When the inputs are the same, the output is 0 (false).
Y=A⊕B=(A⋅B)+(A⋅B)
The symbol ⊕ is the XOR operator. The expression says: "Output is 1 if A is 1 AND B is 0, OR if A is 0 AND B is 1."
The Truth Table
This is the complete, unambiguous definition:
| Input A | Input B | Output Y=A⊕B |
|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Notice the pattern: the output is 1 exactly when the two inputs are different. That's the entire rule.
A common mistake is to confuse XOR with OR. The OR gate outputs 1 when at least one input is 1 — so for A=1,B=1, OR gives 1, but XOR gives 0. XOR is stricter: it demands exactly one input be 1.
Why "Exclusive-OR"?
The name tells the story:
- OR means "at least one is true" — this is the inclusive OR (the usual OR gate).
- Exclusive-OR means "one is true, but the other is excluded" — you cannot have both true.
In everyday language, when you say "You can have coffee or tea," you usually mean exclusive-OR: you can have one, but not both. That's XOR.
A Simple Circuit Analogy
Think of a light bulb controlled by two switches in a special arrangement. The bulb glows only when the two switches are in different positions:
- Switch A up, Switch B down → bulb ON
- Switch A down, Switch B up → bulb ON
- Both up or both down → bulb OFF
That's exactly the XOR behaviour.
Why It Matters …