Brian Kernighan 's algorithm
while ( arr [ i ] != 0 ) : NEW_LINE INDENT arr [ i ] = ( arr [ i ] - 1 ) & arr [ i ] NEW_LINE count += 1 NEW_LINE DEDENT if ( count % 2 == 0 ) : NEW_LINE INDENT even += 1 NEW_LINE DEDENT else : NEW_LINE INDENT odd += 1 NEW_LINE DEDENT return NEW_LINE