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
AB XORXNOR
00 01 Both 0 — same → XNOR=1
01 10 Different → XOR=1
10 10 Different → XOR=1
11 01 Both 1 — same → XNOR=1

Expresión booleana

YXOR=AB=AB+ABY_{XOR} = A \oplus B = A \overline{B} + \overline{A} B

XOR — exactly one of A or B is 1. Two minterms ORed.

YXNOR=AB=AB+ABY_{XNOR} = A \odot B = AB + \overline{A}\overline{B}

XNOR — both same. Either both 1 or both 0.

A1=AA \oplus 1 = \overline{A}

XOR with constant 1 is inversion — XOR is a controllable inverter.

AA=0,A0=AA \oplus A = 0,\quad A \oplus 0 = A

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.

  1. 1
    A = 0 B = 0
    Esperado: XOR = 0, XNOR = 1
    Lo que verás: Inputs match → XNOR fires; XOR stays low. XNOR is the equality detector.
  2. 2
    A = 1 B = 0
    Esperado: XOR = 1, XNOR = 0
    Lo que verás: Inputs differ → XOR fires; XNOR low. The two outputs are always inverses of each other.
  3. 3
    A = 0 B = 1
    Esperado: XOR = 1, XNOR = 0
    Lo que verás: Same as flipping the previous row — XOR is commutative, only the difference matters, not which input is high.
  4. 4
    A = 1 B = 1
    Esperado: XOR = 0, XNOR = 1
    Lo 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.

Preguntas frecuentes

Why is XOR called "exclusive OR"?
Because it returns 1 only when the inputs are mutually exclusive — exactly one of them is 1. Plain OR includes the both-1 case (inclusive OR); XOR excludes it.
How do I build XOR from NAND only?
Four NAND gates: A NAND B feeds into NANDs combined with A and B individually, all merged. The minimal NAND-only XOR uses 4 NAND gates. NOR-only is similar count.
Why is XOR everywhere in cryptography?
Because it's its own inverse — XORing a value with the same key twice returns the original. It's also linear and easily invertible, which makes stream ciphers efficient. The downside (linearity) is why XOR alone is not secure; it's combined with non-linear operations in real ciphers.
Can XOR detect more than one bit flipped?
Standard parity (1 bit) detects an *odd* number of flipped bits but is fooled by an even number. Hamming codes use multiple parity bits to detect and correct multiple errors. CRCs use polynomial XOR for stronger detection in serial protocols.
What's the relationship between XOR and addition?
XOR is addition modulo 2 (single-bit add without carry). The full-adder's sum bit is XOR of three inputs (A, B, carry-in) — that's why XOR appears in every adder cell.

Sigue aprendiendo