求二进制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. }





附件列表

    原文地址:https://www.cnblogs.com/sober-reflection/p/6553450c3bf3ec2d4e9b229844809c2d.html