a+b=x, a|b=y, a&b=z, a^b=k
If x,y,z,k is given, is it possible to find a-b?
a+b=x, a|b=y, a&b=z, a^b=k
If x,y,z,k is given, is it possible to find a-b?
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | jiangly | 3670 |
| 3 | Kevin114514 | 3657 |
| 4 | maroonrk | 3355 |
| 5 | Um_nik | 3353 |
| 6 | squareOf105 | 3346 |
| 7 | tourist | 3343 |
| 8 | strapple | 3324 |
| 9 | heuristica | 3322 |
| 10 | jiangbowen | 3291 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 158 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | AmShZ | 144 |
| 5 | Um_nik | 141 |
| 6 | Errichto | 139 |
| 7 | adamant | 137 |
| 8 | BledDest | 134 |
| 9 | maroonrk | 133 |
| 10 | qwexd | 130 |
| Name |
|---|



If we know, that a|b=y and a&b=z, then we can uniquely determine x and k, using this equations (you can read about it here)
a+b = a|b + a&b
a+b = a⊕b + 2(a&b)
In case we know y and z, determine:
x=y+z
k=x-2z
So from this point, we can use x and k only to check, if there exists a and b, that satisfy bitwise properties.
Let's assume that we find such a and b, that a|b=y and a&b=z, then notice, if we swap i-th bit of a and b, then x, y, z, k will not change, but a-b can
Example:
a=1100
b=1011
a-b=1
let's swap 3-rd bit:
a=1000
b=1111
a-b=-7
Thanks for your reply..
but are you saying that directly getting (a-b) is not possible from the given values?
Yes, a-b can have $$$2^d$$$ different values, where d is the number of bit positions, where a and b are different, so it isn't possible to get directly a-b, knowing only x, y, z, k