Count numbers less than N whose Bitwise AND with N is zero | C ++ program for the above approach ; 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 ; Print the value of 2 to the power of unsetBits ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countUnsetBits ( int N ) { int c = 0 ; while ( N ) { if ( N % 2 == 0 ) { c += 1 ; } N = N >> 1 ; } return c ; } void countBitwiseZero ( int N ) { int unsetBits = countUnsetBits ( N ) ; cout << ( 1 << unsetBits ) ; } int main ( ) { int N = 9 ; countBitwiseZero ( N ) ; return 0 ; }