Math Fundamentals18 sections · 814 units
Open in Course

XOR Properties

Magic of XOR

XOR has properties that make it incredibly useful:

1.1. xx=0x \wedge x = 0 (a number XORed with itself is 0)

2.2. x0=xx \wedge 0 = x (XORing with 0 does nothing)

3.3. XOR is commutative and associative: abc=caba \wedge b \wedge c = c \wedge a \wedge b

These properties let you find unique elements, detect duplicates, and even swap variables without a temporary. If you XOR all numbers in a list where every number appears twice except one, the pairs cancel out (xx=0x \wedge x = 0) and only the unique number remains.