<分区>
Possible Duplicate:
Best algorithm to count the number of set bits in a 32-bit integer?
你好,
有没有更紧凑的方法来计算一个字节中 1 的个数而不使用循环?如果不需要,我不想执行以下操作。谢谢。
char myValue = 0x0F;
int counter = 0;
while (myValue > 0)
{
if (myValue & 0x01)
{
counter ++;
}
myValue = myValue >> 1;
}