Simple Difference Detector
Basic XOR-based difference detector with NOT gate. Simple introduction to change detection using exclusive OR logic.
Lo que aprenderás
- Use XOR as a single-bit difference detector: output is 1 iff inputs differ.
- Use XNOR (or XOR + NOT) as an equality detector: output is 1 iff inputs match.
- Read the 2-bit truth table and identify the difference pattern.
- Recognise that this circuit is the seed of edge detectors and bus comparators.
- Translate "detect change" or "detect mismatch" requirements into XOR-based logic.
Cómo funciona
A difference detector outputs 1 when its inputs disagree and 0 when they agree. The single-bit version is exactly what XOR computes: Y = A ⊕ B is high when A and B differ.
This circuit feeds two switches into an XOR gate. Optionally, a NOT gate inverts the XOR output to provide an "agreement" signal alongside the "difference" signal — that's just XNOR, the equality detector.
Why is this useful? The XOR output is the simplest possible change detector: comparing the current value of a signal to its previous value (held in a flip-flop) tells you whenever the signal flipped. This is the seed of edge-detection circuits, change-data-capture, and many counters.
It's also the building block for bus comparators: extending the same pattern across N bits, AND-reducing the per-bit XNORs gives you an "all bits equal" signal. We'll see this in the multi-bit XOR Difference Detector template.
The XOR truth table is striking in its compactness — only the two "different" rows produce 1, and the two "same" rows produce 0. This pattern mirrors how human eyes detect contrast: we notice difference, not sameness.
Tabla de verdad
Two inputs, two outputs (Diff = XOR, Same = XNOR via NOT). Outputs are always inverses.
| Entradas | Salida | |||
|---|---|---|---|---|
| A | B | Diff | Same | |
| 0 | 0 | 0 | 1 | Both 0 — same → Diff=0, Same=1 |
| 0 | 1 | 1 | 0 | Different → Diff=1 |
| 1 | 0 | 1 | 0 | |
| 1 | 1 | 0 | 1 | Both 1 — same |
Expresión booleana
XOR — high when inputs differ.
XNOR — high when inputs match. Just XOR followed by NOT.
Always exactly one output is high — the two are perfect complements.
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:
Diff = 0, Same = 1Lo que verás: Both switches off — Diff is dark, Same is bright. The inputs match (both 0). - 2A = 1 B = 0Esperado:
Diff = 1, Same = 0Lo que verás: One switch on, one off — Diff fires. The inputs disagree. - 3A = 1 B = 1Esperado:
Diff = 0, Same = 1Lo que verás: Both switches on — back to agreement. Same fires, Diff goes dark. The two outputs always swap together. - 4A = 0 B = 1Esperado:
Diff = 1, Same = 0Lo que verás: Difference detected again — XOR is symmetric in inputs.
Componentes utilizados
Aplicaciones en el mundo real
Change-data-capture for digital signals. Comparing a signal's current value with its registered previous value via XOR yields a 1-clock-wide pulse on every edge. Used to count edges, trigger interrupts, or sample asynchronous events.
Bus equality comparators. N-bit comparators in CPUs use a per-bit XNOR followed by AND-reduction: "all bits equal" means "all XNORs high." Used in branch comparison instructions and tag matching in caches.
Parity bits. A single XOR over all data bits produces the even-parity bit. Receiver XORs again to detect single-bit corruption.
Stream cipher decryption. Encrypted bit XORed with the same keystream bit recovers the plaintext. Difference detection is at the heart of how stream ciphers work.
Phase comparison in PLLs. XOR of two clocks of the same frequency produces a duty-cycle that depends on phase difference — a simple linear phase detector.