I compute
c = a 'OR' b // bitwise OR operation here
Now given only values of c
and b
how can I compute the original value of a
?
The bitwise NOT operator in C++ is the tilde character ~ . Unlike & and |, the bitwise NOT operator is applied to a single operand to its right. Bitwise NOT changes each bit to its opposite: 0 becomes 1, and 1 becomes 0.
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 ( ~ ). Save this answer.
The ~ (bitwise negation) operator yields the bitwise complement of the operand. In the binary representation of the result, every bit has the opposite value of the same bit in the binary representation of the operand.
Bitwise NOT (~) The bitwise NOT operator ( ~ ) inverts the bits of its operand. Like other bitwise operators, it converts the operand to a 32-bit signed integer.
This is impossible.
A simple case to demonstrate my point (assuming a, b, and c are all 1-bit):
If 'b' is 1, 'c' will always be 1, you cannot determine the value of 'a'.
You cannot reliably go back. For example, a = 0010 and b = 0011. a OR b = 0011. The same result is true if a was different (0001 or 0011 for example).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With