compute number of 1 bits in a binary representation of a number
C/C++
int popcnt(int n)
{
    return __builtin_popcount(n);
}

For some CPUs __builtin_popcount compiles to a single instruction (e.g. POPCNT on x86).
Note: requires gcc or gcc-compatible compiler (e.g. ICC).