i could do with third variable
c=a|b;
a=c&a;
b=c&a;
But i need to do it without third variable. I tried using XOR it wasn't helping me either.
i could do with third variable
c=a|b;
a=c&a;
b=c&a;
But i need to do it without third variable. I tried using XOR it wasn't helping me either.
it's an easy 1st year programming class question:
a = a^b;
b = a^b;
a = a^b;
XOR has a property that XORing something twice always brings you back to where you started. You can use this fact to switch variables in three assignments without a third variable.
int a = 54;
int b = 23;
a = a XOR b; // (a XOR b)
b = a XOR b; // (a XOR b) XOR b = a
a = a XOR b; // (a XOR b) XOR a = b