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 | Kevin114514 | 3659 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3382 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3312 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 155 |
| 2 | nik_exists | 151 |
| 3 | maspy | 149 |
| 4 | AmShZ | 145 |
| 5 | Um_nik | 143 |
| 6 | Errichto | 139 |
| 7 | BledDest | 136 |
| 8 | adamant | 134 |
| 9 | maroonrk | 132 |
| 10 | cry | 130 |
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?
| 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