Reverse AND operation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vpawizard
    New Member
    • Nov 2006
    • 66

    #1

    Reverse AND operation

    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?
  • tavianator
    New Member
    • Dec 2006
    • 38

    #2
    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.

    Comment

    • vpawizard
      New Member
      • Nov 2006
      • 66

      #3
      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.

      Comment

      • DeMan
        Top Contributor
        • Nov 2006
        • 1799

        #4
        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.....

        Comment

        • tavianator
          New Member
          • Dec 2006
          • 38

          #5
          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.

          Comment

          Working...