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
< ? php function isPowerOfTwo ( $ x ) { $ y = 0 ; if ( $ x && ( ! ( $ x & ( $ x - 1 ) ) ) ) $ y = 1 ; return $ y ; } function differAtOneBitPos ( $ a , $ b ) { return isPowerOfTwo ( $ a ^ $ b ) ; } $ a = 13 ; $ b = 9 ; if ( differAtOneBitPos ( $ a , $ b ) ) echo " Yes " ; else echo " No " ; ? >