XOR Operation
Exclusive OR: true when exactly one input is true.
Formula
Variables
Example
1 ⊕ 1 = 0
How it works
The XOR operation compares two Boolean values and outputs 1 only when they differ. The expression (a ∨ b) ∧ ¬(a ∧ b) captures that idea by first checking that at least one input is true, then removing the case where both are true. In other words, it keeps the "one or the other" cases and excludes the "both" case.
When to use it
Use XOR when you need to detect a difference between two bits, such as in parity checks, simple adders, error detection, and bit toggling. It also appears in programming and digital logic whenever a condition should be true for exactly one of two possibilities.
Worked example, step by step
Let a = 1 and b = 0 Step 1: a ∨ b = 1 ∨ 0 = 1 Step 2: a ∧ b = 1 ∧ 0 = 0 Step 3: ¬(a ∧ b) = ¬0 = 1 Step 4: (a ∨ b) ∧ ¬(a ∧ b) = 1 ∧ 1 = 1 Final answer: 1 ⊕ 0 = 1
Common mistakes to avoid
- Thinking XOR means "at least one true"; that is OR, not XOR
- Forgetting that XOR is false when both inputs are true
- Mixing up XOR with AND when working with bitwise operations in code
Did You Know?
XOR is reversible — apply it twice with the same key and you get the original back, the basis of simple ciphers.
Share this formula
More in Computer Science
View allShannon Entropy
AdvancedAverage information content of a random source (bits).
Master Theorem (form)
AdvancedAnalyzes running time of divide-and-conquer algorithms.
Hamming Distance
AdvancedNumber of positions at which two strings differ.
Bits to Represent n
BasicMinimum number of bits to represent n distinct values.
Binary to Decimal
BasicConverts a binary number to decimal.
Nodes in a Full Binary Tree
IntermediateTotal nodes in a perfect binary tree of height h.