Count numbers less than N whose Bitwise AND with N is zero | Function to count number of unset bits in the integer N ; Stores the number of unset bits in N ; Check if N is even ; Increment the value of c ; Right shift N by 1 ; Return the value of count of unset bits ; Function to count numbers whose Bitwise AND with N equal to 0 ; Stores the number of unset bits in N ; Prthe value of 2 to the power of unsetBits ; Driver Code
def countUnsetBits ( N ) : NEW_LINE INDENT c = 0 NEW_LINE while ( N ) : NEW_LINE INDENT if ( N % 2 == 0 ) : NEW_LINE INDENT c += 1 NEW_LINE DEDENT N = N >> 1 NEW_LINE DEDENT return c NEW_LINE DEDENT def countBitwiseZero ( N ) : NEW_LINE INDENT unsetBits = countUnsetBits ( N ) NEW_LINE print ( ( 1 << unsetBits ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 9 NEW_LINE countBitwiseZero ( N ) NEW_LINE DEDENT