배울 내용

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

작동 원리

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.

진리표

Both gates have 4 input rows. XOR fires on the two "different" rows; XNOR fires on the two "same" rows. They are exact inverses.

입력 출력
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

불 대수식

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.

단계별로 시도해 보세요

위 임베드에서 입력을 설정한 후, 예상 결과를 읽고 직접 확인하세요.

  1. 1
    A = 0 B = 0
    예상: XOR = 0, XNOR = 1
    관찰 포인트: Inputs match → XNOR fires; XOR stays low. XNOR is the equality detector.
  2. 2
    A = 1 B = 0
    예상: XOR = 1, XNOR = 0
    관찰 포인트: Inputs differ → XOR fires; XNOR low. The two outputs are always inverses of each other.
  3. 3
    A = 0 B = 1
    예상: XOR = 1, XNOR = 0
    관찰 포인트: Same as flipping the previous row — XOR is commutative, only the difference matters, not which input is high.
  4. 4
    A = 1 B = 1
    예상: XOR = 0, XNOR = 1
    관찰 포인트: Both 1 → XOR is 0 (this is what makes it "exclusive" OR — unlike OR, both-on doesn't fire it).

사용된 구성 요소

실제 응용 사례

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.

자주 묻는 질문

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.

학습 계속하기