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 ; Print the value of 2 to the power of unsetBits ; Driver Code
function countUnsetBits ( N ) { let c = 0 ; while ( N != 0 ) { if ( N % 2 == 0 ) { c += 1 ; } N = N >> 1 ; } return c ; } function countBitwiseZero ( N ) { let unsetBits = countUnsetBits ( N ) ; document . write ( 1 << unsetBits ) ; } let N = 9 ; countBitwiseZero ( N ) ;