I had difficulty simplifying the following function in several atomic binary operations, it seems to me that this is possible, but I can’t do this, I have been scratching my head a little for several hours:
public UInt32 reverse_xor_lshift(UInt32 y, Int32 shift)
{
var x = y & (UInt32)((1 << shift) - 1);
for (int i = 0; i < (32 - shift); i++) {
var bit = ((x & (1 << i)) >> i) ^ ((y & (1 << (shift + i))) >> (shift + i));
x |= (UInt32)(bit << (shift + i));
}
return x;
}
what the function does is simply calculate the inverse Z = X ^ (X << Y), in other wordsreverse_xor_lshift(Z, Y) == X
source
share