Find XOR of two number without using XOR operator | Returns XOR of x and y ; Assuming 32 - bit Integer ; Find current bits in x and y ; If both are 1 then 0 else xor is same as OR ; Update result ; Driver program to test above function
function myXOR ( x , y ) { for ( let i = 31 ; i >= 0 ; i -- ) { let b1 = ( ( x & ( 1 << i ) ) == 0 ) ? 0 : 1 ; let b2 = ( ( y & ( 1 << i ) ) == 0 ) ? 0 : 1 ; let xoredBit = ( b1 & b2 ) ? 0 : ( b1 b2 ) ; res <<= 1 ; res |= xoredBit ; } return res ; } let x = 3 , y = 5 ; document . write ( " " + myXOR ( x , y ) ) ;