= Exclusive or
{title2=XOR}
{title2=$P\oplus Q$}
{wiki}
= Bitwise exclusive or
{synonym}
= XOR
{c}
{synonym}
<Exclusive or> returns one exactly when its two input <bits> differ. Its <truth table> gives $0\oplus0=0$, $0\oplus1=1$, $1\oplus0=1$, and $1\oplus1=0$. The identities
$$
P\oplus Q=(P\vee Q)\wedge\neg(P\wedge Q)
=(P\wedge\neg Q)\vee(\neg P\wedge Q)
$$
express <exclusive or> using <logical conjunction>, <logical disjunction>, and <logical negation>. The first expression accepts at least one input and then excludes both; the second explicitly lists the two accepted input pairs.
For numerical <bits>, <exclusive or> is <addition> in <modular arithmetic> modulo two:
$$
x\oplus y=(x+y)\bmod2.
$$
The <binary operation> is <commutative> and <associative>, because <addition> modulo two has those properties. It satisfies $x\oplus0=x$, $x\oplus1=\neg x$, and $x\oplus x=0$. These identities explain why a <bit> can be toggled and restored with the same operation.
On <binary strings> of equal length, bitwise <exclusive or> applies the one-<bit> rule separately at each position. For example,
$$
1010\oplus0110=1100,\qquad1100\oplus0110=1010.
$$
A <bit mask> of $0110$ toggles exactly the middle two <bits>. Applying the mask twice restores the original <binary string>: each selected <bit> changes twice, and each unselected <bit> stays fixed. This positional operation is distinct from taking the <exclusive or> of the overall <truth values> of two <integers>.
Back to article page