#include <iostream>
using namespace std;
int func(int x)
{
int count = 0;
while(x)
{
count ++;
x=x&(x-1);
}
return count;
}
int main()
{
cout<< func(15) << endl;
return 0;
}
结果是4.
二进制中包含1的数量
最新推荐文章于 2023-01-05 18:08:53 发布