From point #2: x & x = 0
if and only if x = 0
, so (2 * a) & a = 0
. Since multiplying by 2 is a single bit shift, we can see that this is true for any number that doesn't have two set bits next to each other.
From point #3: x & x <= 0
if and only if x <= 0
, so that means a ^ b <= 0
. If a ^ b = 0
that would mean a = b
but point #1 doesn't allow that because 3997
is odd. Thus, a ^ b < 0
which means a
and b
differ in the sign bit, that is one is positive or zero, the other is negative.
These leave us some freedom of choice. For point #2 we can simply pick a power of 2 that is greater than 3997
, then calculate the other number by subtracting from 3997
. For example, a = 4096
, b = -99
:
- 4096 + (-99) = 3997
- ((2 * 4096) & 4096) & ((2 * 4096) & 4096) = 0
- (4096 ^ -99) & (4096 ^ -99) = -4195
There are many other solutions.