# Solving for a and b from xor and difference

Can we solve for a and b, from

$$a-b = x$$

$$a \oplus b = y$$

Even when x and y can be negative?

I tried substituting the value of a in xor equation from the difference,

$$\Rightarrow (b+x)\oplus b = y$$

Since $$b \oplus b$$ is 0

$$\Rightarrow x \oplus b = y$$

But, then how to solve for b?

• Unfortunately your method does not work, because you are assuming that $\oplus$ distributes across addition in $(b + x) \oplus b = x \oplus b$, which it certainly does not. – Jeremy Dover Feb 14 at 4:57
• okay, Jeremy, That's helpful. But then how to proceed this? – Aniket Bhushan Feb 14 at 6:07
• By solving for $b$ in the second equation and substituting into the first, you can see $a-x = a \oplus y$. This shows that the equations do not have a solution if $x$ and $y$ have opposite parity. Another easy case is if $y=1$, then all even $a$ are a solution if $x=-1$, and all odd $a$ are a solution if $x=1$. No other values of $x$ yield solutions when $y=1$. Because $\oplus$ and $+$ are both nonlinear over the additive group generated by the other, there is no general way to solve these equations. – Jeremy Dover Feb 14 at 13:10