XOR and XNOR Gate Explorer
Comprehensive XOR and XNOR gate demonstration. Learn exclusive OR logic and its complement. Essential for understanding difference detection and parity.
Lo que aprenderás
- Distinguish XOR (difference detector) from OR (any-of detector).
- Recognise XNOR as the equality detector — XOR's inverse.
- Read both 2-input truth tables and identify the row pattern.
- Use the identity A ⊕ 1 = ¬A — XOR as a controllable inverter.
- Apply XOR for parity, comparison, encryption, and adder sum bits.
Cómo funciona
XOR (exclusive OR) is the gate of *difference*: its output is high when its inputs differ, and low when they agree. With two inputs A and B, the output is 1 if exactly one of them is 1, and 0 otherwise. Boolean expression: Y = A ⊕ B = A·¬B + ¬A·B.
XNOR (exclusive NOR) is the inverse: output is high when inputs *agree*, low when they differ. It's literally NOT-XOR — the equality detector. Y = A ⊙ B = ¬(A ⊕ B) = A·B + ¬A·¬B.
These two gates are special because they're not minterms — they require both AND and OR (or three NANDs) to build. But they're so widely useful that they're treated as primitives in most logic libraries.
Key properties: - XOR is commutative (A ⊕ B = B ⊕ A) and associative ((A ⊕ B) ⊕ C = A ⊕ (B ⊕ C)). - A ⊕ 0 = A (XOR with 0 is identity — pass-through). - A ⊕ 1 = ¬A (XOR with 1 inverts — XOR is a controllable inverter!). - A ⊕ A = 0 (XOR with itself is always 0 — useful in encryption and hashing).
Wide N-input XORs compute odd parity: output is 1 if an odd number of inputs are 1. This is the basis of parity-bit error detection in transmitted data.
Tabla de verdad
Both gates have 4 input rows. XOR fires on the two "different" rows; XNOR fires on the two "same" rows. They are exact inverses.
| Entradas | Salida | |||
|---|---|---|---|---|
| A | B | XOR | XNOR | |
| 0 | 0 | 0 | 1 | Both 0 — same → XNOR=1 |
| 0 | 1 | 1 | 0 | Different → XOR=1 |
| 1 | 0 | 1 | 0 | Different → XOR=1 |
| 1 | 1 | 0 | 1 | Both 1 — same → XNOR=1 |
Expresión booleana
XOR — exactly one of A or B is 1. Two minterms ORed.
XNOR — both same. Either both 1 or both 0.
XOR with constant 1 is inversion — XOR is a controllable inverter.
Two XOR identities used heavily in cryptography.
Pruébalo paso a paso
Configura las entradas en la simulación de arriba, lee qué debería suceder y verifícalo.
- 1A = 0 B = 0Esperado:
XOR = 0, XNOR = 1Lo que verás: Inputs match → XNOR fires; XOR stays low. XNOR is the equality detector. - 2A = 1 B = 0Esperado:
XOR = 1, XNOR = 0Lo que verás: Inputs differ → XOR fires; XNOR low. The two outputs are always inverses of each other. - 3A = 0 B = 1Esperado:
XOR = 1, XNOR = 0Lo que verás: Same as flipping the previous row — XOR is commutative, only the difference matters, not which input is high. - 4A = 1 B = 1Esperado:
XOR = 0, XNOR = 1Lo que verás: Both 1 → XOR is 0 (this is what makes it "exclusive" OR — unlike OR, both-on doesn't fire it).
Componentes utilizados
Aplicaciones en el mundo real
Parity-bit error detection. Serial protocols append a parity bit so the receiver can check XOR of all data bits + parity bit equals 0. A single bit flip changes parity and is detected.
Comparators. XNOR(A, B) = 1 means A == B. A bus comparator AND-reduces an array of XNORs across the bus: all-equal means all-XNORs-high.
Stream cipher encryption. XOR with a pseudo-random keystream encrypts; XOR with the same keystream decrypts. Used in WPA2, ChaCha20, and many block-cipher modes.
Adder sum bit. A full-adder's sum bit is XOR of the two inputs and the carry: S = A ⊕ B ⊕ Cin. This is XOR's most common appearance inside CPUs.
Phase comparators in PLLs. XOR phase detectors compare two clock signals — output duty cycle indicates phase difference.
Gray-code conversion. Binary-to-Gray and Gray-to-binary use XOR with shifted versions. Gray code is essential for rotary encoders where only one bit changes per step.