XOR and XNOR Truth Tables With Examples
XOR outputs 1 when its inputs differ; XNOR outputs 1 when they match. Both truth tables, a two-switch demo, three-input parity and bitwise code examples.
XOR (exclusive OR) outputs 1 when exactly one input is 1, that is, when the inputs differ. XNOR is its inverse: it outputs 1 when the inputs are the same.
| A | B | A XOR B | A XNOR B |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
Flip the two switches to light up the matching row:
How XOR differs from OR
Ordinary OR is 1 when at least one input is 1, so 1 OR 1 = 1. XOR excludes that last case: 1 XOR 1 = 0. A handy way to say it is “one or the other, but not both”. A hallway light with a switch at each end behaves like XOR: flipping either switch changes the light.
As a Boolean expression, XOR is A·B̅ + A̅·B (A and not B, or not A and B), and XNOR is A·B + A̅·B̅ (both 1, or both 0). In circuit diagrams XOR is written ⊕ and XNOR ⊙ or as ⊕ with a bar over it.
XNOR is an equality test
Because XNOR is 1 exactly when its inputs match, it compares bits. Comparing two bytes bit by bit with XNOR yields all ones only when the bytes are identical. Hardware comparators are built from XNOR gates for this reason.
Three or more inputs: XOR is parity
Chain XOR across several bits and the result is 1 when an odd number of inputs are 1. That is the parity bit used in simple error detection.
| A | B | C | A ⊕ B ⊕ C | Ones |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 2 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | 2 |
| 1 | 1 | 0 | 0 | 2 |
| 1 | 1 | 1 | 1 | 3 |
Bitwise XOR on whole numbers
Programming languages apply XOR to every bit position at once with the ^ operator. These results come from Python 3.14.3; JavaScript gives the same values.
>>> 0b1100 ^ 0b1010
6 # 0110: bits that differ
>>> 0x5A ^ 0xFF
165 # 0xA5: XOR with all ones flips every bit
>>> 0x5A ^ 0x5A
0 # anything XOR itself is 0
>>> (0x5A ^ 0x3C) ^ 0x3C
90 # 0x5A again: XOR twice with the same key undoes it
Most languages have no XNOR operator. Compute it as the complement of XOR, then mask to the width you care about: ~(a ^ b) & 0xFF in Python or JavaScript gives the 8-bit XNOR.
Where XOR is used
- Flipping selected bits.
value ^ masktoggles exactly the bits set in the mask and leaves the others alone. - Detecting changes.
old ^ newhas a 1 in every position that changed. - Parity and checksums. XOR of all bytes gives a one-byte check value; RAID 5 stores XOR parity across disks so a lost block can be rebuilt.
- Binary addition. In a half adder, the sum bit is A XOR B and the carry is A AND B. Try it in the binary addition calculator.
The bitwise calculator runs AND, OR, XOR and NOT on any two binary numbers and shows the result bit by bit.
Sources
- Binary bitwise operations — Python Language Reference. section 6.9
- Bitwise XOR (^) — MDN
How we made this
Computed and checked by tests. Truth tables are generated from the ^ operator by the widget code (src/lib/calc/logic.js) and asserted in tests. The byte and parity examples were run in Python 3.14.3 and Node.js 25 and the printed results are quoted.
Performed by Claude, an AI assistant working in the BinConvert repository (Python 3.14.3, Node.js 25), November 16, 2026.
This article was drafted with AI assistance. Every example, calculation and command output on this page was re-run or checked before release; tables and code outputs were regenerated and compared. Review: automated test suite and source check, November 16, 2026.
Spotted an error? Tell us and we will correct it.