Connecting Tech Pros Worldwide Forums | Help | Site Map

Reverse AND operation

vpawizard's Avatar
Member
 
Join Date: Nov 2006
Posts: 66
#1: Jan 3 '07
Hello,
I have two numbers x and y. x & y are ANDed together to produce z. I know the values of z and y. Is there any way to retrieve the value of x?

Member
 
Join Date: Dec 2006
Posts: 38
#2: Jan 4 '07

re: Reverse AND operation


Just think about it:

if y == 0 and z==0, x could be anything; therefore there is no reverse and operation.

In general:

if y == 0, then z== 0, and x could be anything
if y == 1 and z == 0, x = 0
if y == 1 and z == 1, x = 1

use xor for a reversable operation.
vpawizard's Avatar
Member
 
Join Date: Nov 2006
Posts: 66
#3: Jan 4 '07

re: Reverse AND operation


Well I am aware of the XOR operation. However, the case is some operation is returning me the ANDed value and I have to extract the first operand and all I know is the result of ANDing and the second operand for AND.
DeMan's Avatar
Lives Here
 
Join Date: Nov 2006
Location: Adelaide, SA
Posts: 1,748
#4: Jan 4 '07

re: Reverse AND operation


If you do come up with an answer, however, please post, as prime numbers show some interesting behaviour in logic arithmetic, so being able to undo logical operations could be a really powerful thing to do.....
Member
 
Join Date: Dec 2006
Posts: 38
#5: Jan 4 '07

re: Reverse AND operation


Unfortunately, that is impossible in the general case. If any bit of y is 0, then you cannot reverse the operation. And if all bits of y are 1, then x & y == x, so an algorythm that finds the inverse of the bitwise (or logical) and operation is basically useless.
Reply