I'm having trouble writing a bitwise XNOR function with at most 7 ~ and | operators. Example: bitXnor(6, -5) = 2. How do I do this without &?
So far I have this:
int bitXnor(int x, int y) {
return ~(~x | ~y);
but I'm getting the error:
ERROR: Test bitXnor(-2147483648[0x80000000],-2147483648[0x80000000]) failed...
...Gives -2147483648[0x80000000]. Should be -1[0xffffffff]
Negate (
~) either parameter and XOR them (^)