+ 1

How do i revert a value created using bitwise operator '|'?

For example, int a = 3; int b = 5; int c = a | b; so the value for c will be 7 as per bitwise operator rules. So how can one change value of c after removing value of b and as a result get value of a and visa versa

27th Feb 2017, 8:41 AM
Apurva Dubal
Apurva Dubal - avatar
1 Réponse
+ 1
Impossible because different operands may result in the same value. Can you determine x in the equation x * 0 = 0 ? As you say, 3 | 5 is 7. Likewise, 3 | 4, 3 | 6, and 3 | 7 is also 7. So if 7 and 3 given, the other operand can be 4, 5, 6 or 7. No way to determine which is the original. You can list all possibilities instead, but I don't think it is what you want.
27th Feb 2017, 10:32 AM
Twelfty
Twelfty - avatar