How do I change the bitwise OR operation?

Here's what I did:

93 | 199

      

which returns

223

      

I understand that this is because there 0b1011101 | 0b11000111

is0b11011111

However, suppose I want to do the opposite. How to get 0b1011101

from bitwise operation between 0b11000111

and 0b11011111

?

+3


source to share


2 answers


You cannot get a definite answer in the general case. If C=A|B

, then wherever you have a 1 in C and a 1 in A, the corresponding bit of B can be either 0 or 1.



In your example, 93 | 199 = 223, but 92 | 199 is also 223. So given 223 and 199 there is no single answer (in fact, there are 32 possible answers in this example).

+13


source


As stated here , both OR and AND are destructive . The reverse OR operation is a lossy operation, and as "jez" mentioned, there can be more than one response. So it is not possible



Only the reverse operation is possible for XOR, since it is non-destructive .

0


source







All Articles