454,911 Members | 1,134 Online
Need help? Post your question and get tips & solutions from a community of 454,911 IT Pros & Developers. It's quick & easy.

# Reverse AND operation

 P: 66 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? Jan 3 '07 #1
4 Replies

 P: 38 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. Jan 4 '07 #2

 P: 66 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. Jan 4 '07 #3

 100+ P: 1,806 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..... Jan 4 '07 #4

 P: 38 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. Jan 4 '07 #5