The exclusive disjunction or XOR of two operands is true when exactly one of them is true. Equivalently, true when the operands are different.

Image: XOR gate symbol, Public domain — exclusive-OR gate (ANSI/IEEE symbol).

000
011
101
110

For more than two operands, XOR is true when an odd number of operands are true. That’s why it’s also called “parity”: exactly when an odd number of the are .

XOR is the negation of XNOR: same input pattern, complemented output. The corresponding hardware element is the XOR gate.

Where it shows up

XOR is the workhorse of binary arithmetic. The sum bit of a Half-adder is , exactly the XOR truth table. The sum bit of a Full-adder extends to , again pure XOR.

XOR also appears whenever you want a controlled inverter: , but . That’s how a 2’s-complement adder/subtractor uses XOR gates to optionally complement the second operand based on a Sub control bit.

Notation and identities

Symbol in electronics is . In formal logic, emphasizes XOR being the negation of .

In SOP form, , true exactly when one variable is set and the other isn’t.

A three-variable identity that comes up in MUX-based logic synthesis:

where is the XNOR. The right-hand side is the parity of three variables. The left-hand side is exactly what a 2-to-1 MUX with select , data inputs (line 1) and (line 0) computes. So three-input parity can be built from one XOR + one XNOR + one MUX. Useful when MUXes are cheaper than wide XOR gates (typical in FPGA synthesis).

Useful properties of XOR:

  • Self-inverse:
  • Identity for :
  • Commutative and associative — order doesn’t matter

These make XOR good for one-time-pad-style operations: , so XORing twice with the same key recovers the original.