How to reverse bitwise AND (&) in C?

VaioIsBorn picture VaioIsBorn · Apr 2, 2010 · Viewed 11.5k times · Source

How to reverse bitwise AND (&) in C?

For example I have an operation in C like this:

((unsigned int)ptr & 0xff000000))

The result is 0xbf000000. What I need at this moment is how to reverse the above, i.e. determine ptr by using the result from the operation and of course 0xff000000.

Is there any simple way to implement this in C?

Answer

Andrey picture Andrey · Apr 2, 2010

Bitwise & can't be reversed:

0 & 1 = 0
0 & 0 = 0