Convert binary 1 number

Title Description
Enter an integer and output the number of 1s in the binary representation of the number. Negative numbers are represented by complements.

在这里插入代码片
public int NumberOf1(int n) {
        int a=0;
      while(n!=0)
      {if((n&1)==1)
              a++;
      n=n>>>1;}
        return a;
    }

note:
Insert picture description here

Published 152 original articles · praised 16 · 30,000+ views

Guess you like

Origin blog.csdn.net/feiqipengcheng/article/details/105278717