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 allGustafson’s Law
IntermediateIdeal scaled-workload speedup when more processors allow a larger parallel task in the same elapsed time. Here s is the serial fraction of the parallel execution time, not the single-processor fraction used in Amdahl’s law.
Hick–Hyman Law (Equal Choices)
IntermediateModels choice reaction time for n equally likely alternatives (n ≥ 1). This information-theoretic form assumes comparable, practised stimulus–response choices; it is not a universal law of menu browsing.
Fitts’s Law (Shannon Form)
IntermediateAn empirical model of aimed movement time: farther or narrower targets generally take longer to reach. Use D ≥ 0, W > 0 and fitted coefficients for the device and task.
Shannon 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.