, , . . , :
unsigned int i4_xor ( unsigned int i, unsigned int j )
{
unsigned int i2;
unsigned int j2;
unsigned int k;
unsigned int l;
k = 0;
l = 1;
while ( i != 0 || j != 0 )
{
i2 = i / 2;
j2 = j / 2;
if (
( ( i == 2 * i2 ) && ( j != 2 * j2 ) ) ||
( ( i != 2 * i2 ) && ( j == 2 * j2 ) ) )
{
k = k + l;
}
i = i2;
j = j2;
l = 2 * l;
}
return k;
}
i8_xor. .
, DailyWTF .
EDIT: , , , :
function xor i:unsigned, j:unsigned
answer = 0
bit_position = 1
while i <> 0 or j <> 0
if least significant bit of i <> least significant bit of j
answer = answer + bit_position
end if
bit_position = bit_position * 2
i = i / 2
j = j / 2
end while
return answer
end function
, - , :
bit set if i <> (i / 2) * 2
bit clear if i == (i / 2) * 2
WTFy , C XOR, "^". , :
result = i4_xor (a, b);
:
result = a ^ b; // no function call at all!
xor. ( , C), XOR .