If you take a look at your x
/y
/x'
example, it must strike you that x'
is a complement to y
. And indeed it's like that.
x y x'
--------
1 1 0
0 0 1
1 0 1
0 1 0
Spoiler (hover your mouse over block below, if you want to see a solution):
For bits that match, you invert bit in
x
, but as it is the same as bit iny
, it's the same as inverting bit iny
. When they do not match, you keep the bit fromx
, what is already inversion of bit iny
on its own. I hope you can see the one-line solution already yourself:x' = ~y;