XOR (Exclusive Or) — Definition, Formula & Examples
XOR (Exclusive Or) is a logical operator that outputs true when exactly one of its two inputs is true, but not both. If both inputs match (both true or both false), XOR outputs false.
Given two propositions and , the exclusive disjunction is defined as . Equivalently, is true if and only if and have different truth values.
Key Formula
Where:
- = First proposition (true or false)
- = Second proposition (true or false)
- = XOR operator (exclusive or)
- = OR operator (inclusive disjunction)
- = AND operator (conjunction)
- = NOT operator (negation)
How It Works
XOR compares two statements and asks: are these different? To evaluate , check the truth values of and . If one is true and the other is false, the result is true. If both are true or both are false, the result is false. You can remember this by thinking of the word "exclusive" — it excludes the case where both inputs are true, unlike the regular OR (disjunction) which includes it. XOR appears constantly in computer science for tasks like toggling bits, error detection, and encryption.
Worked Example
Problem: Let p = "It is raining" (True) and q = "It is sunny" (True). Evaluate p ⊕ q.
Step 1: Evaluate the inclusive OR: p ∨ q.
Step 2: Evaluate the AND: p ∧ q.
Step 3: Negate the AND result.
Step 4: Combine using AND to get the final XOR result.
Answer: p ⊕ q is False. Since both p and q are true, XOR returns false — they are not exclusively different.
Another Example
Problem: Let p = True and q = False. Evaluate p ⊕ q.
Step 1: Evaluate the inclusive OR.
Step 2: Evaluate the AND and negate it.
Step 3: Combine to get XOR.
Answer: p ⊕ q is True. Exactly one input is true, so XOR returns true.
Why It Matters
XOR is essential in discrete mathematics courses and AP Computer Science, where it shows up in logic proofs and circuit design. In cryptography, XOR is the backbone of many encryption algorithms because applying it twice with the same key restores the original data. Bit-level XOR operations are also used in error-detecting codes, hash functions, and competitive programming problems.
Common Mistakes
Mistake: Treating XOR the same as regular OR and saying both-true gives true.
Correction: XOR specifically excludes the both-true case. When p and q are both true, is false. Only regular OR () returns true in that scenario.
Mistake: Forgetting that XOR of two false inputs is also false.
Correction: XOR requires exactly one true input. Two false inputs means the values are the same (not different), so XOR returns false.
