Overview
The XOR gate, short for exclusive OR, is a fundamental digital logic element that produces a true (1) output when the number of true inputs is odd. For the common two-input case, the gate outputs 1 only when exactly one input is 1. In formal logic this operation is known as an exclusive disjunction, and in digital design it is one of several basic logic gate types used to build more complex circuits.
Function and truth table
For two inputs, A and B, the XOR can be described by the expression: A ⊕ B = (A AND NOT B) OR (NOT A AND B). It is equivalent to addition modulo two: the output is 1 when A and B differ. The two-input truth table is often shown as:
- A=0, B=0 → Output=0
- A=0, B=1 → Output=1
- A=1, B=0 → Output=1
- A=1, B=1 → Output=0
For more than two inputs the XOR returns 1 when an odd number of inputs are 1; this is also called an odd-parity function.
Mathematical properties
XOR has several useful algebraic properties: it is commutative and associative, has 0 as an identity element (X ⊕ 0 = X), and it is self-inverse (X ⊕ X = 0). These properties make XOR a linear operation over the two-element field GF(2), which underlies many digital arithmetic and coding techniques.
History and notation
The exclusive OR concept arose from formal logic and early switching algebra. Notation varies: ⊕ is common in mathematics, while many programming languages use the caret (^) or a keyword for the bitwise XOR operation. The logic symbol used in circuit diagrams is typically an OR gate shape with an added curved line on the input side to indicate exclusivity.
Applications and examples
XOR is central to digital arithmetic and error detection. In binary adders the half-adder computes the sum bit as A ⊕ B while the carry uses A AND B. Parity generators and checkers use XOR to produce parity bits that detect single-bit errors. In cryptography XOR is widely used as a simple mixing operation—combining plaintext and a key stream is equivalent to XORing bit sequences (as in stream ciphers and the one-time pad). In software, XOR is available as a bitwise operator for integer types and is useful for toggling bits and simple checksums.
Implementation and notable facts
Physically, XOR can be implemented directly in CMOS or TTL logic, or synthesized from combinations of AND, OR and NOT gates. Unlike NAND or NOR, XOR by itself is not functionally complete, but its algebraic simplicity and parity behavior make it indispensable in digital systems. For more technical resources see a general logic gates guide: logic gates reference and a discussion of the exclusive disjunction: exclusive disjunction.