简体   繁体   中英

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;

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM