Activity 2.3.5 — XOR & XNOR Gates¶
Learning Objectives¶
By the end of this lesson, students will be able to:
- Describe the difference between XOR and XNOR gates and identify their unique truth tables.
- Apply XOR properties to simplify Boolean expressions.
- Explain how XOR gates are used in binary addition and comparison applications.
- Build and verify XOR and XNOR circuits using logic gates.
Vocabulary¶
Vocabulary (click to expand)
| Term | Definition |
|---|---|
| XOR (Exclusive OR) | A logic gate that produces a HIGH output only when the inputs are different (one HIGH, one LOW). |
| XNOR (Exclusive NOR) | A logic gate that produces a HIGH output only when the inputs are the same (both HIGH or both LOW). |
| Parity | A property of binary numbers describing whether the number of 1s is odd or even. |
| Odd Parity | The condition where the number of 1s in a binary word is odd. |
| Even Parity | The condition where the number of 1s in a binary word is even. |
| Inequality Detector | A circuit that produces a HIGH output when inputs are different. |
Part 1: XOR Gate Fundamentals¶
The XOR (Exclusive OR) gate is a fundamental building block in digital electronics. Unlike the standard OR gate, the XOR gate produces a HIGH output only when the inputs are different.
XOR Truth Table¶
| A | B | Y = A xor B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Key Observation¶
XOR is HIGH when: - A = 0 and B = 1 (inputs are DIFFERENT) - A = 1 and B = 0 (inputs are DIFFERENT)
XOR is LOW when: - A = 0 and B = 0 (both are the same - both LOW) - A = 1 and B = 1 (both are the same - both HIGH)
Key insight: XOR is a "difference detector" - it outputs 1 when the inputs differ, and 0 when they're the same.
XOR Symbol¶
The XOR gate uses the symbol A ⊕ B (where ⊕ is the XOR operator):
Part 2: XNOR Gate Fundamentals¶
The XNOR (Exclusive NOR) gate is the complement of XOR. It produces a HIGH output when the inputs are the same.
XNOR Truth Table¶
| A | B | Y = A xnor B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Key Observation¶
XNOR is HIGH when: - A = 0 and B = 0 (both are LOW - SAME) - A = 1 and B = 1 (both are HIGH - SAME)
XNOR is LOW when: - A = 0 and B = 1 (inputs are DIFFERENT) - A = 1 and B = 0 (inputs are DIFFERENT)
Key insight: XNOR is an "equality detector" or "coincidence detector" - it outputs 1 when inputs match.
XNOR Symbol¶
XNOR is often written as A ⊙ B or (A ⊕ B)':
Part 3: XOR Properties and Algebra¶
The XOR operation has several useful properties that can simplify circuit design:
XOR Properties¶
| Property | Expression | Description |
|---|---|---|
| Identity | A ⊕ 0 = A | XOR with 0 returns A |
| Inverse | A ⊕ 1 = A' | XOR with 1 inverts A |
| Idempotent | A ⊕ A = 0 | XOR with itself = 0 |
| Inverse Property | A ⊕ A' = 1 | XOR with complement = 1 |
| Commutative | A ⊕ B = B ⊕ A | Order doesn't matter |
| Associative | (A ⊕ B) ⊕ C = A ⊕ (B ⊕ C) | Grouping doesn't matter |
XOR Implementation with Basic Gates¶
XOR can be implemented using basic gates:
This translates to: - One AND gate with A and B' (A AND NOT B) - One AND gate with A' and B (NOT A AND B) - One OR gate combining the two AND outputs
A----|\
& |\
B'---| )---+--- Y
|/ |
B-----------+ (wait, this isn't right)
Actually:
A----|\
& |\
B'---| )---+---\
A'---|/ )---+--- Y
B ----------|/
Key insight: The XOR expression A ⊕ B = A·B' + A'·B shows it's the sum of the cases where one input is 1 and the other is 0.
Part 4: Applications of XOR¶
Binary Addition (Half Adder)¶
One of the most important applications of XOR is in binary addition. The SUM bit of a half adder is exactly XOR of the two inputs:
| A | B | Sum (A ⊕ B) | Carry (A·B) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
The Sum output = A ⊕ B The Carry output = A · B
Comparison / Equality Detection¶
XOR can be used to compare two bits: - If A ⊕ B = 0, then A = B - If A ⊕ B = 1, then A ≠ B
Extending this to multiple bits requires checking if all XOR outputs are 0.
Parity Checking¶
Parity is used for error detection: - Even parity: Number of 1s in the word is even (including parity bit) - Odd parity: Number of 1s in the word is odd (including parity bit)
An XOR chain can count the number of 1s: - Even number of 1s → XOR output = 0 - Odd number of 1s → XOR output = 1
7486 Quad XOR IC¶
The 7486 is a quad 2-input XOR IC containing four independent XOR gates:
- Package: 14-pin DIP
- Four 2-input XOR gates
- Useful for building comparators, adders, and parity generators
Part 5: XNOR Applications¶
XNOR is essentially an inverted XOR, making it useful for:
Equality Comparison¶
XNOR outputs 1 when inputs match, making it perfect for checking if two bits are equal: - A ⊙ B = 1 means A = B
Inverting Selector¶
XNOR acts as an inverting data selector: - When select = 0: output = input - When select = 1: output = input' (inverted)
Parity (Even)¶
XNOR can be used for even parity checking: - Even number of 1s → XNOR output = 1
Key insight: XOR and XNOR are inverses of each other. XNOR = (XOR)' and XOR = (XNOR)'.
Practice Problem — XOR Truth Table Verification¶
Problem: Complete the truth table and verify the XOR pattern:
| A | B | A ⊕ B |
|---|---|---|
| 0 | 0 | ? |
| 0 | 1 | ? |
| 1 | 0 | ? |
| 1 | 1 | ? |
Show Solution
| A | B | A ⊕ B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
XOR = 1 only when inputs are different.
Practice Problem — Simplify XOR Expressions¶
Problem 1: Simplify A ⊕ 0
Problem 2: Simplify A ⊕ A
Problem 3: Simplify A ⊕ A'
Show Solution
Problem 1: A ⊕ 0 = A (Identity property: XOR with 0 returns the other input)
Problem 2: A ⊕ A = 0 (Idempotent property: XOR with itself equals 0)
Problem 3: A ⊕ A' = 1 (Inverse property: XOR with complement equals 1)
Practice Problem — Build XOR with Basic Gates¶
Problem: Draw the gate-level circuit to implement A ⊕ B using AND, OR, and NOT gates.
Show Solution
The Boolean expression is: A ⊕ B = A·B' + A'·B
Steps: 1. Create B' using NOT gate on B 2. Create A' using NOT gate on A 3. AND A with B' → first term (A·B') 4. AND A' with B → second term (A'·B) 5. OR the two terms → final output
Practice Problem — XOR in Binary Addition¶
Problem: For a half adder with inputs A=1 and B=1: a) What is the SUM output? b) What is the CARRY output?
Show Solution
a) SUM = A ⊕ B = 1 ⊕ 1 = 0 b) CARRY = A · B = 1 · 1 = 1
Result: 1 + 1 = 10 (binary), meaning SUM = 0 and CARRY = 1
Practice Problem — XNOR Application¶
Problem: How would you use an XNOR gate to detect if two bits A and B are equal?
Show Solution
Simply connect A and B to the XNOR gate inputs. The output will be 1 when A = B (both 0 or both 1), indicating equality.
Truth table: - A=0, B=0 → XNOR = 1 (equal) - A=0, B=1 → XNOR = 0 (not equal) - A=1, B=0 → XNOR = 0 (not equal) - A=1, B=1 → XNOR = 1 (equal)
Summary¶
- XOR produces HIGH only when inputs are different; XNOR produces HIGH when inputs are the same.
- XOR (A ⊕ B) = A·B' + A'·B; XNOR = (XOR)' = A·B + A'·B'
- Useful XOR properties: A⊕0=A, A⊕1=A', A⊕A=0, A⊕A'=1
- XOR is used in half adders (SUM output) and comparison circuits.
- XNOR is used for equality detection and even parity checking.
- The 7486 is a quad 2-input XOR IC.
Key Reminders¶
- XOR = "difference detector" (1 when different)
- XNOR = "equality detector" (1 when same)
- Remember the XOR Boolean expression: A ⊕ B = A·B' + A'·B
- XOR gates are essential for building arithmetic circuits.
- Parity checking uses XOR to detect errors in data transmission.
Custom activity — adapted from PLTW Digital Electronics