位1的个数

Posted wangyufeng99

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了位1的个数相关的知识,希望对你有一定的参考价值。

public class Solution 
    // you need to treat n as an unsigned value
    public int hammingWeight(int n) 
       int count = 0;
       while (n != 0) 
       count += n & 1;
       n = n >>> 1;
   
       return count;
    

以上是关于位1的个数的主要内容,如果未能解决你的问题,请参考以下文章