When studying Android audio system, I saw a interest function code in google’s AndioSystem class:
uint32_t AudioSystem::popCount(uint32_t u)
{
u = ((u&0x55555555) + ((u>>1)&0x55555555));
u = ((u&0x33333333) + ((u>>2)&0x33333333));
u = ((u&0x0f0f0f0f) + ((u>>4)&0x0f0f0f0f));
u = ((u&0x00ff00ff) + ((u>>8)&0x00ff00ff));
u = ( u&0x0000ffff) + (u>>16);
return u;
}
Honestly, I cannot understand how this code come from. Fortunately, the code leave a reference link for us: http://www.df/lth/se/~john_e/gems/gem002d.html.
And telling the trust again, for me, it’s still hard to understand after reading the reference algorithm. So, I decide to make a node, and just copy the code when I need it ~ .