学べること

  • 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.

仕組み

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.

真理値表

Two inputs, two outputs (Diff = XOR, Same = XNOR via NOT). Outputs are always inverses.

入力 出力
AB DiffSame
00 01 Both 0 — same → Diff=0, Same=1
01 10 Different → Diff=1
10 10
11 01 Both 1 — same

ブール式

Diff=AB\text{Diff} = A \oplus B

XOR — high when inputs differ.

Same=AB=AB\text{Same} = \overline{A \oplus B} = A \odot B

XNOR — high when inputs match. Just XOR followed by NOT.

Diff+Same=1\text{Diff} + \text{Same} = 1

Always exactly one output is high — the two are perfect complements.

順を追って試す

上の埋め込み回路で入力を設定し、期待される結果と一致するか確認しましょう。

  1. 1
    A = 0 B = 0
    期待値: Diff = 0, Same = 1
    観察ポイント: Both switches off — Diff is dark, Same is bright. The inputs match (both 0).
  2. 2
    A = 1 B = 0
    期待値: Diff = 1, Same = 0
    観察ポイント: One switch on, one off — Diff fires. The inputs disagree.
  3. 3
    A = 1 B = 1
    期待値: Diff = 0, Same = 1
    観察ポイント: Both switches on — back to agreement. Same fires, Diff goes dark. The two outputs always swap together.
  4. 4
    A = 0 B = 1
    期待値: Diff = 1, Same = 0
    観察ポイント: Difference detected again — XOR is symmetric in inputs.

使用コンポーネント

実世界での応用

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.

よくある質問

Why use XOR + NOT instead of XNOR directly?
Educational clarity — it shows that XNOR is literally NOT(XOR). In production circuits where both signals are needed, an XNOR primitive is often more efficient than XOR + inverter (one less gate). Most cell libraries provide both.
Can I scale this to multi-bit comparison?
Yes — that's the XOR Difference Detector template. Use one XOR per bit, then either OR-reduce (any-bit-different) or AND-reduce after inverting (all-bits-equal). Both patterns are common.
What is edge detection and how does this relate?
Edge detection compares a signal's current value to its delayed (registered) value using XOR. Output = 1 for one clock cycle whenever the signal changes — a perfect rising-or-falling edge pulse. Used to count button presses, debounce inputs, and trigger one-shot actions.
Is this circuit synchronous or asynchronous?
Asynchronous (combinational) — output reflects inputs immediately, with only gate-propagation delay. To make it synchronous (sampled to a clock), feed both inputs through flip-flops first. The XOR itself doesn't change.
What's the cheapest CMOS XOR layout?
About 8 transistors using a transmission-gate XOR (4-T XOR + 4-T select), or 12-T using static CMOS. A NAND-only build takes 4 NAND2 = 16 transistors. Transmission-gate XOR is the gold standard in custom layouts.

学習を続ける