Find two numbers from their sum and OR | Python 3 program for the above approach ; Function to find the two integers from the given sum and Bitwise OR value ; Check if Z is non negative ; Iterate through all the bits ; Find the kth bit of A & B ; Find the kth bit of A | B ; If bit1 = 1 and bit2 = 0 , then there will be no possible pairs ; Print the possible pairs ; Driver Code
MaxBit = 32 NEW_LINE def possiblePair ( X , Y ) : NEW_LINE INDENT Z = Y - X NEW_LINE if ( Z < 0 ) : NEW_LINE INDENT print ( " - 1" ) NEW_LINE return 0 NEW_LINE DEDENT for k in range ( MaxBit ) : NEW_LINE INDENT bit1 = ( Z >> k ) & 1 NEW_LINE bit2 = ( Z >> k ) & 1 NEW_LINE if ( bit1 == 1 and bit2 == 0 ) : NEW_LINE INDENT print ( " - 1" ) NEW_LINE return 0 NEW_LINE DEDENT DEDENT print ( Z , X ) NEW_LINE return 0 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT X = 7 NEW_LINE Y = 11 NEW_LINE possiblePair ( X , Y ) NEW_LINE DEDENT