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
function CountZeroBit ( x ) { let count = 0 ; while ( x > 0 ) { if ( ( x & 1 ) == 0 ) count ++ ; x >>= 1 ; } return count ; } function CountXORandSumEqual ( x ) { let count = CountZeroBit ( x ) ; return ( 1 << count ) ; } let x = 10 ; document . write ( CountXORandSumEqual ( x ) ) ;