Find two numbers from their sum and OR | Javascript 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
let MaxBit = 32 ; function possiblePair ( X , Y ) { let Z = Y - X ; if ( Z < 0 ) { document . write ( " " ) ; return 0 ; } for ( let k = 0 ; k < MaxBit ; k ++ ) { let bit1 = ( Z >> k ) & 1 ; let bit2 = ( Z >> k ) & 1 ; if ( bit1 && ! bit2 ) { document . write ( " " ) ; return 0 ; } } document . write ( Z + " " + X ) ; return 0 ; } let X = 7 , Y = 11 ; possiblePair ( X , Y ) ;