Tuesday, July 12, 2011

Bitwise XOR Operator

A number XORed with the another number twice will give the original number.I tried this sample program in Linux and it working fine.

#include
void main()
{
int i=23,j;
i=i^50;
printf("\nAfter 1st shift the value of i = %d\n",i);
i=i^50;
printf("\nAfter 2nd shift the value of i = %d\n",i);
if(i==23)
printf("\nInitial value= Final Value ---> SUCCESS\n");
else printf("\nSOMETHING WRONG IN THE PROGRAM\n");
}


The output will be

After 1st shift the value of i = 37

After 2nd shift the value of i = 23

Initial value= Final Value ---> SUCCESS

No comments:

Post a Comment