求二进制1的个数

  1. int BitCount2(unsigned int n)
  2. {
  3. unsigned int c =0 ;
  4. for (c =0; n; ++c)
  5. {
  6. n &= (n -1) ; // 清除最低位的1
  7. }
  8. return c ;
  9. }





附件列表

     

    posted @ 2015-01-29 11:31  sober_reflection  阅读(127)  评论(0编辑  收藏  举报