What are some practical applications of XOR in algorithms

Honestly, I'm rusty in bit operations.
I'm interested in the operation XOR. Well, I know that it is beaten, and that it is used in encryption and that we can exchange without any time variable, but I was wondering if the algorithms have specific approaches that match the properties XOR.
I mean, I'm interested in practical applications XORin algorithms (for example, we could use it to find a unique element among duplicates). Is there a problem of problems (or a statement of the problem) that you can see that use XORis the way to go? (Just as there is a pattern when to use binary search?)
Is there a list of practical applicationsXORfor algorithms related to the main algorithm, and not just use it, for example. do math operations faster, as we can use >>instead of dividing by 2.

Any input is welcome

+5
source share
1 answer

A few examples that arose in my head:

Bit Switching:

int i = 123;
i ^= (1 << 4); // toggle bit 5

Some kind of accident:

int i = 123;
for (int k = 0; k < 100; k++)
{
   i = i ^ (i << 1) + i;
   System.out.println(i);
}

Weak Encryption:

int b = 235321;
int key = 24552;
int encrypted = b ^ key;
int decrypted = encrypted ^ key; // equals 235321
+8
source

All Articles