Find two numbers from their sum and XOR | Function that takes in the sum and XOR of two numbers and generates the two numbers such that the value of X is minimized ; Traverse through all bits ; Let us leave bits as 0. ; else : ( Xi == 1 and Ai == 1 ) ; Driver function
def compute ( S , X ) : NEW_LINE INDENT A = ( S - X ) // 2 NEW_LINE a = 0 NEW_LINE b = 0 NEW_LINE for i in range ( 64 ) : NEW_LINE INDENT Xi = ( X & ( 1 << i ) ) NEW_LINE Ai = ( A & ( 1 << i ) ) NEW_LINE if ( Xi == 0 and Ai == 0 ) : NEW_LINE INDENT pass NEW_LINE DEDENT elif ( Xi == 0 and Ai > 0 ) : NEW_LINE INDENT a = ( ( 1 << i ) a ) NEW_LINE b = ( ( 1 << i ) b ) NEW_LINE DEDENT elif ( Xi > 0 and Ai == 0 ) : NEW_LINE INDENT a = ( ( 1 << i ) a ) NEW_LINE print ( " Not ▁ Possible " ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( " a ▁ = ▁ " , a ) NEW_LINE print ( " b ▁ = " , b ) NEW_LINE DEDENT S = 17 NEW_LINE X = 13 NEW_LINE compute ( S , X ) NEW_LINE