XOR counts of 0 s and 1 s in binary representation | Java program to find XOR of counts 0 s and 1 s in binary representation of n . ; Returns XOR of counts 0 s and 1 s in binary representation of n . ; calculating count of zeros and ones ; Driver Program
class GFG { static int countXOR ( int n ) { int count0 = 0 , count1 = 0 ; while ( n != 0 ) { if ( n % 2 == 0 ) count0 ++ ; else count1 ++ ; n /= 2 ; } return ( count0 ^ count1 ) ; } public static void main ( String [ ] args ) { int n = 31 ; System . out . println ( countXOR ( n ) ) ; } }