Reputation: 9959
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
?
Upvotes: 8
Views: 10250
Reputation: 14738
Since a OR 1 is always 1 and a OR 0 is always a you can only find the value of a if b is 0.
Edit: AND and OR are lossy operations (cannot always be reversed). Whereas XOR and NOT are lossless/reversible.
Upvotes: 4
Reputation: 19392
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'.
Upvotes: 25
Reputation: 700212
That's not possible, the or operation is not reversible. There are many different values of a that give the same value for c.
You can get one possible value of a by doing an and operation with the complement of b.
a = c & ~b
Upvotes: 4
Reputation: 7870
from a mathematic point of view it is just not possible to deduce A from C and B. if, for the nth bit you have the value 1 in C and in B you can't know if the nth bit in A equals 0 or 1
Upvotes: 1
Reputation: 3454
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).
Upvotes: 5
Reputation: 171744
That's not possible. There is no way to determine what 'a' will be
Upvotes: 1