1. XOR as aparity / “single‑odd‑one‑out” shortcut
The discussion repeatedly points out that XOR can isolate the lone element when every other value appears an even number of times (or 0 mod n times). The technique generalises to “even‑count cancel, odd‑count remains” and can be expressed as digit‑wise addition modulo n.
"given a list where every value appears exactly twice except one, XOR all the values together and the duplicates cancel out, leaving the unique element" – ranger_danger
"every value but one must appear even numbers of times, and the one must appear some odd number of times." – fluoridation
"every value appears 0 mod n times except one which appears 1 mod n times? :)" – twiceaday
"xor is just addition mod 2. Write the numbers in base n and do digit‑wise addition mod n (ie without carry). Very intuitive way to see the xor trick." – Solution
2. The classic XOR‑swap trick and its historical/technical context
Many comments focus on the three‑statement XOR swap, its undefined‑behaviour edge cases, and why it survives mainly as a “party‑trick” or interview‑question rather than a practical optimisation. Users note its relevance to older SIMD/instruction‑set constraints and its modern irrelevance. > "The XOR trick is only cool in its undefined‑behavior form: a^=b^=a^=b;" – gobdovan
"xor swap trick was useful in older simd (sse1/sse2) when based on some condition you want to swap values or not:" – mmozeiko > "you can still manually do it in C for bonus stylistic points!" – gobdovan
"It still is... The CPU's register renamer can detect these instructions to not have data dependencies and can zero the register itself." – pjc50
3. Creative / extended uses of XOR beyond simple swapping
The thread branches into various non‑trivial applications: XOR‑linked lists, error‑correction codes, multi‑port RAM constructions, and even a one‑time‑pad‑like scheme for distributing “pure‑noise” shares. These illustrate XOR’s utility as a lightweight parity or reconstruction primitive.
"You can use this same property of xor to make a double‑linked list using just one pointer per item, which is xor of the previous and next item addresses!" – stinkbeetle
"error correction... add one additional packetz = a ^ b ^ c. Now whenever one ofa,b, orcgets corrupted … it can be reconstructed by computing the XOR of all the others." – danhau
"store copyrighted works without liability…c = a ^ b. Givebto a friend … both end up with pure noise that together yields the original work." – amelius > "XOR‑linked list … https://en.wikipedia.org/wiki/XOR_linked_list" – throwaway2027