Search code examples
algorithmxor

Determine numbers based on their sum and xor


If we know the sum and XOR of two numbers, then can we find out what are the two numbers?

I am trying to resolve a problem and the above problem is a part of that. Although, I do have another solution for that problem but I still want a solution for this.


Solution

  • No.

    Example: SUM=7, XOR=7
    Possible answers:
    a) 1, 6
    b) 2, 5
    c) 3, 4

    Not enough information to decide which pair (a, b or c) is the original pair of numbers.