• • XOR Magic in programming is well known. The Exclusive-OR boolean expression is widely used in digital circuits. Today we will discuss its benefits and uses in computer programming. Boolean expression of XOR is From the truth table it is clear that if we do XOR of two equal value then the output would be 0 otherwise 1. Let us learn some interesting use of XOR.

• XOR to swap two distinct values without using third variable.
```#include<stdio.h>

int main ()
{
int a = 2;
int b = 3;
printf ("Before swap a = %d and b = %d\n", a, b);

// swap a and b
a = a ^ b;
b = b ^ a;
a = a ^ b;

printf ("Before swap a = %d and b = %d\n", a, b);

return 0;
}

output:
Before swap a = 2 and b = 3
Before swap a = 3 and b = 2
```
```#include <iostream>
using namespace std;

int
main ()
{
char text = "hello world";
char key = 'P';
for (int i = 0; i < 12; i++)
{
text[i] = text[i] ^ key;
}
// print encrypted text
cout << "encrted text is :";
cout << text << endl;

cout << "decrypted text :";
for (int i = 0; i < 12; i++)
{
text[i] = text[i] ^ key;
}

cout << text << endl;
return 0;
}
```

Ref:

https://en.wikipedia.org/wiki/XOR_swap_algorithm