Count numbers whose sum with x is equal to XOR with x | Function to find total 0 bit in a number ; Function to find Count of non - negative numbers less than or equal to x , whose bitwise XOR and SUM with x are equal . ; count number of zero bit in x ; power of 2 to count ; Driver code ; Function call
def CountZeroBit ( x ) : NEW_LINE INDENT count = 0 NEW_LINE while ( x ) : NEW_LINE INDENT if ( ( x & 1 ) == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT x >>= 1 NEW_LINE DEDENT return count NEW_LINE DEDENT def CountXORandSumEqual ( x ) : NEW_LINE INDENT count = CountZeroBit ( x ) NEW_LINE return ( 1 << count ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT x = 10 NEW_LINE print ( CountXORandSumEqual ( x ) ) NEW_LINE DEDENT