Twisted89
Twisted89

Reputation: 446

reverse bit operations

Just a quick one here, is it possible to find the original values of aValue and bValue from i? and if so how?

Thanks.

uint i = Convert.ToUInt32((aValue << 2) & 0x300) | bValue;

Upvotes: 0

Views: 344

Answers (2)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726489

It is not possible to find the pair of values from i, because multiple pairs could produce identical results.

It is easy to see if you consider an example where all bits of bValue are set. Then all bits of i will be set as well, regardless of the value of aValue. Now consider the situation when every odd bit of aValue is set, every even bit of bValue is set, and also the least significant bit of bValue is set. Again, the result will have all its bits set, for a very different pair of aValue and bValue.

aValue=00110011, bValue=11111111 ---> i=11111111
aValue=10110000, bValue=11111111 ---> i=11111111
aValue=00000000, bValue=11111111 ---> i=11111111
aValue=01010101, bValue=10101011 ---> i=11111111

Upvotes: 1

YoryeNathan
YoryeNathan

Reputation: 14512

Many values can produce the same result.

Even if you had one of the values, you couldn't still be sure about the other one, not always, because information is lost during the operation, which is irreversible.

Upvotes: 0

Related Questions