Count set bits of X
while ( X != 0 ) { X = ( X - 1 ) & X ; count ++ ; } if ( count % 2 == 0 ) { document . write ( even + " " + odd + " " ) ; } else { document . write ( odd + " " + even + " " ) ; } } }