Count numbers whose sum with x is equal to XOR with x | Java 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
import java . io . * ; class GFG { static long CountZeroBit ( long x ) { long count = 0 ; while ( x > 0 ) { if ( ( x & 1L ) == 0 ) count ++ ; x >>= 1L ; } return count ; } static long CountXORandSumEqual ( long x ) { long count = CountZeroBit ( x ) ; return ( 1L << count ) ; } public static void main ( String [ ] args ) { long x = 10 ; System . out . println ( CountXORandSumEqual ( x ) ) ; } }