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 program
' NEW_LINE def areAllBitsSet ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT if ( ( ( n + 1 ) & n ) == 0 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT return False ; NEW_LINE DEDENT def isOnesComplementOfOther ( a , b ) : NEW_LINE INDENT return areAllBitsSet ( a ^ b ) NEW_LINE DEDENT a = 1 NEW_LINE b = 14 NEW_LINE if ( isOnesComplementOfOther ( a , b ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT