XOR counts of 0 s and 1 s in binary representation | Returns XOR of counts 0 s and 1 s in binary representation of n . ; calculating count of zeros and ones ; Driver Code
< ? php function countXOR ( $ n ) { $ count0 = 0 ; $ count1 = 0 ; while ( $ n ) { ( $ n % 2 == 0 ) ? $ count0 ++ : $ count1 ++ ; $ n = intval ( $ n / 2 ) ; } return ( $ count0 ^ $ count1 ) ; } $ n = 31 ; echo countXOR ( $ n ) ; ? >