计算二进制数中1的个数

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

 

posted @ 2016-08-28 17:32  绿水白川  阅读(102)  评论(0编辑  收藏  举报