We basically count set bits https : www . geeksforgeeks . org / count - set - bits - in - an - integer /
$ parity = 0 ; while ( $ x != 0 ) { $ x = ( $ x & ( $ x - 1 ) ) ; $ parity ++ ; } if ( $ parity % 2 == 0 ) return true ; else return false ; }