built in popcount c++

C++
 __builtin_popcount(n))
Source

Also in C++: