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
< ? php function CountZeroBit ( $ x ) { $ count = 0 ; while ( $ x ) { if ( ! ( $ x & 1 ) ) $ count ++ ; $ x >>= 1 ; } return $ count ; } function CountXORandSumEqual ( $ x ) { $ count = CountZeroBit ( $ x ) ; return ( 1 << $ count ) ; } $ x = 10 ; echo CountXORandSumEqual ( $ x ) ; ? >