The gate that fires when exactly one of its inputs is on. A plain-English guide to logic gates from TorchAnvil.
An XOR gate — "exclusive or" — has two inputs and one output. The output is high when exactly one input is high. If both inputs match (both off, or both on), the output is zero.
Think of XOR as the answer to "are these two inputs different?" If A and B disagree, XOR fires. If they agree, it stays silent. It's the difference detector of digital logic.
| A | B | A ⊕ B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
The ⊕ symbol is a plus inside a circle — addition, modulo 2. That's the
most useful way to think about XOR: it's binary addition where you throw
the carry away. 1 ⊕ 1 = 0 because 1 + 1 = 2, and 2 mod 2 is 0.
XOR has a strange, lovely set of superpowers that pop up everywhere:
1 ⊕ 1 = 0 is exactly what a sum bit
should do when two 1s add and roll over — that's why it's half of a
half adder.X ⊕ 1 = NOT X, X ⊕ 0 = X. One input becomes a "flip
me" switch for the other.Add two single bits, A and B. The result needs two outputs, because
1 + 1 is 10 in binary and won't fit in one:
| A | B | Sum | Carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
Look at the Sum column: that's XOR exactly. Look at Carry: that's AND exactly.
Sum = A ⊕ BCarry = A · BTwo gates and you have a half adder — a circuit that genuinely does arithmetic. Chain two of them plus an OR and you get a full adder that accepts a carry in; chain four of those and you can add any two numbers from 0 to 15. That is the entire path from one XOR gate to a working calculator, and there is nothing else hiding in it.
XOR is its own inverse, which is unusual and extremely useful:
(X ⊕ K) ⊕ K = X
Apply a value twice and you're back where you started. This one identity underpins a surprising amount of computing:
a ^= b; b ^= a; a ^= b
leaves them exchanged.They agree on three rows and differ on the last one:
| A | B | OR | XOR |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 |
English is unhelpful here. "Tea or coffee?" means one or the other — XOR. "Bring a coat or an umbrella" allows both — OR. Since everyday speech uses "or" for both meanings, your intuition can't be trusted; check the both-on row deliberately every time.
XOR is the first gate in Minecraft that actually takes some thought — there's no one-block version. The usual build uses a pair of torches that cancel each other out when both inputs match, lighting only when the inputs disagree.
Expressed in gates, the common redstone XOR is:
(A OR B) AND NOT(A AND B) — "at least one, but not both"which is why it needs more components than anything else on this list. The XOR redstone pattern has the canonical layout with a footprint and a bill of materials.
A ⊕ B = (A + B) · NOT(A · B)A ⊕ B = (A · NOT B) + (NOT A · B) — the sum-of-products form, read
straight off the two rows where the output is 1.(A ⊕ B) ⊕ C equals
A ⊕ (B ⊕ C), and both equal "an odd number of inputs are high". That
is what makes parity trees work at any width.The demo on the right is one XOR between two levers, feeding a lamp. Flip one lever and the lamp lights. Flip the other one also on, and the lamp goes dark — exactly one is no longer true.
Then add an AND across the same two levers and a second lamp. You've built a half adder: the first lamp is the sum, the second is the carry.