Exclusive disjunction (XOR)
Exclusive disjunction, or XOR, is a logical operation true when exactly one input is true. It appears in Boolean algebra, digital circuits, cryptography, and parity checks.
Overview
Exclusive disjunction, commonly called exclusive OR or XOR, is a basic logical operation that returns true precisely when one of its inputs is true and the other is false. It contrasts with the ordinary inclusive or, which allows both inputs to be true. XOR is widely used in Boolean algebra and digital design and appears in programming as a bitwise operator.
The operation is often written with symbols such as ⊻ or ⊕. In formal writing it may be described as a binary logical operation or a binary algebraic operation on two values. A concise mnemonic is: "one or the other, but not both."
Image gallery
1 ImageDefinition and truth table
XOR takes two inputs and yields a single output. The result is true exactly when the inputs differ. A short truth table follows:
- Input A = false, Input B = false -> Output = false
- Input A = false, Input B = true -> Output = true
- Input A = true, Input B = false -> Output = true
- Input A = true, Input B = true -> Output = false
Properties and algebraic forms
Algebraically, XOR can be seen as addition modulo 2: 1 XOR 1 = 0, 1 XOR 0 = 1, and so on. It is commutative (A XOR B = B XOR A) and associative ((A XOR B) XOR C = A XOR (B XOR C)), allowing multi-input XORs to be defined. XOR is its own inverse: applying the same value twice cancels it out (A XOR A = false). These properties make it useful for toggling and error-detection schemes.
Uses and examples
XOR appears in many practical contexts. In digital electronics it is implemented as an XOR gate for conditional selection and arithmetic circuits. In computer programming languages it commonly exists as a bitwise operator that flips bits where operands differ. Cryptographic constructions and simple stream ciphers use XOR because of its reversibility: data XOR key = cipher, and cipher XOR key = data. Parity bits and checksum methods employ XOR to detect single-bit errors.
Distinctions and notable facts
The key distinction is between exclusive and inclusive disjunction; inclusive OR returns true when one or both inputs are true, while XOR requires exactly one true input. XOR is also distinct from logical implication and equivalence: equivalence (XNOR) yields true when inputs are equal, the logical complement of XOR. For further reading on related operations, see discussions of inclusive disjunction and Boolean connectives: inclusive disjunction.
These characteristics make XOR a compact and versatile primitive in logic, arithmetic circuits, and many algorithms that rely on difference, parity, or reversible encoding.
Related articles
Author
AlegsaOnline.com Exclusive disjunction (XOR) Leandro Alegsa
URL: https://en.alegsaonline.com/art/32895