Count numbers whose sum with x is equal to XOR with x | C # program to count numbers whose bitwise XOR and sum with x are equal ; 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
using System ; class GFG { static int CountZeroBit ( int x ) { int count = 0 ; while ( x > 0 ) { if ( ( x & 1 ) == 0 ) count ++ ; x >>= 1 ; } return count ; } static int CountXORandSumEqual ( int x ) { int count = CountZeroBit ( x ) ; return ( 1 << count ) ; } static public void Main ( ) { int x = 10 ; Console . WriteLine ( CountXORandSumEqual ( x ) ) ; } }