How to reverse bitwise AND (&) in C?

前端 未结 4 1793
一生所求
一生所求 2020-12-06 01:21

How to reverse bitwise AND (&) in C?

For example I have an operation in C like this:

((unsigned int)ptr & 0xff000000))

The

相关标签:
4条回答
  • 2020-12-06 01:22

    You can't do that because you have thrown away information (i.e. bits) - you can't get information back from nowhere.

    Note that both AND (&) and OR (|) are destructive. The only Boolean operations that are reversible are XOR (^) and NOT (~).

    0 讨论(0)
  • 2020-12-06 01:40

    Impossible. Bitwise & of 0xff000000 is a lossy operation. You lose the lower 24-bits permanently.

    0 讨论(0)
  • 2020-12-06 01:41

    You can only reverse XOR, as it's non-destructive.

    Both OR and AND are destructive.

    0 讨论(0)
  • 2020-12-06 01:46

    Bitwise & can't be reversed:

    0 & 1 = 0
    0 & 0 = 0
    
    0 讨论(0)
提交回复
热议问题