Check whether the two numbers differ at one bit position only | function to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; function to check whether the two numbers differ at one bit position only ; Driver code
function isPowerOfTwo ( x ) { return x != 0 && ( ( x & ( x - 1 ) ) == 0 ) ; } function differAtOneBitPos ( a , b ) { return isPowerOfTwo ( a ^ b ) ; } let a = 13 , b = 9 ; if ( differAtOneBitPos ( a , b ) == true ) document . write ( " " ) ; else document . write ( " " ) ;