#include <stdlib.h>
#include <string.h>
/*
功能:
输入:整型
输出:
返回:返回1的个数
*/
int GetCount(int iValue)
{
int count = 0;
while (iValue)
{
count++;
iValue &= (iValue-1);
}
return count;
}求一个数的二进制的1的个数
本文介绍了一个函数,用于计算整型数值中1的个数,通过位操作实现效率提升。

被折叠的 条评论
为什么被折叠?



