Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of Bitwise OR operation

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?

like image 939
Kapil Avatar asked Jul 08 '09 06:07

Kapil


People also ask

What is opposite of bitwise and?

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.

Can bitwise and be reversed?

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.

What is a bitwise negation?

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.

What is not bitwise?

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.


2 Answers

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'.

like image 182
Cambium Avatar answered Sep 22 '22 20:09

Cambium


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).

like image 28
joeslice Avatar answered Sep 18 '22 20:09

joeslice