Is this the correct way to prove bitwise operation statement

54 Views Asked by At

I have this following question:

If x xor 6 = y xor 6 then x=y

I tried proving:

My prove is: suppose x = y+1 and x is even and y is odd => x xor 6 = (xxx0)(base 2) and y xor 6 = (xxx1) (base 2) so x is not equal to y.

Is this the correct proof? Is there any other way to prove?

And will the statement change if 6 is replaced by 7?

Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

You don't want to mix addition and XOR as addition carries and XOR does not. If you work in binary $x \operatorname{XOR} 6$ is $x$ with the twos bit and the fours bit inverted. As $\operatorname{XOR}$ is associative and $0$ is the identity you can just say $$x \operatorname{XOR} 6=y\operatorname{XOR}6\\(x\operatorname{XOR}6)\operatorname{XOR}6=(y\operatorname{XOR}6)\operatorname{XOR}6\\x\operatorname{XOR}(6\operatorname{XOR}6)=y\operatorname{XOR}(6\operatorname{XOR}6)\\ x\operatorname{XOR}0=y\operatorname{XOR}0\\x=y$$ You can change $6$ to any number with the same result.