求一个数转化成二进制后包含1的个数

求一个数转化成二进制后包含1的个数

1 int func(int x){
2     int count=0;
3     while(x){
4         count++;
5         x=x&(x-1);
6     }
7     return count;
8 }

猜你喜欢

转载自www.cnblogs.com/zpcoding/p/10314386.html