The code from the Wikipedia article for XOR swapping [1] checks if the values are equal.
void XorSwap(int *x, int *y) {
if (x != y) {
*x ^= *y;
*y ^= *x;
*x ^= *y;
}
}
[1] https://en.wikipedia.org/wiki/XOR_swap_algorithm