- Theory
- XOR returns true only if two boolean operands are different
- XOR is equivalent to (A AND !B) OR (!A AND B)
- Parentheses are optional as AND operator takes precedence
- Implementation
- Java XOR operator uses ^ symbol as bitwise operator
- Bitwise XOR compares matching bits of values
- Same-position bits result in 0, different-position bits in 1
- Works with all primitive types
- Example
- XORing 1 and 3 results in 2 (binary 00000010)
- Only second bit differs between numbers