Check if one of the numbers is one 's complement of the other | function to check if all the bits are set or not in the binary representation of ' n ' ; all bits are not set ; if true , then all bits are set ; else all bits are not set ; function to check if one of the two numbers is one 's complement of the other ; Driver Code
< ? php function areAllBitsSet ( $ n ) { if ( $ n == 0 ) return false ; if ( ( ( $ n + 1 ) & $ n ) == 0 ) return true ; return false ; } function isOnesComplementOfOther ( $ a , $ b ) { return areAllBitsSet ( $ a ^ $ b ) ; } $ a = 10 ; $ b = 5 ; if ( isOnesComplementOfOther ( $ a , $ b ) ) echo " Yes " ; else echo " No " ; ? >