`
wss71104307
  • 浏览: 218597 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

一个32位无符号整数中1bit的数目

 
阅读更多
//求1的个数
int  num1Bit(int x)
{
  for(int count=0; x;count++)
   { 
         x &= x-1;
   }
}
//求0的个数
int  num1Bit(int x)
{
  for(int count=32; x;count--)
   { 
         x &= x-1;
   }
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics