public class c2_1 {
public static int Count1(int x){
int num=0;
while(x!=0){
if( x%2 == 1 ) num++;
x/=2;
}
return num;
}
public static int Count2(int x){
int num=0;
while(x!=0){
num += x & 0x11;
x>>=1;
}
return num;
}
public static int Count3(int x){
int num=0;
while(x!=0){
x &= (x-1);
num++;
}
return num;
}
public static void main(String args[]){
int x=6;
System.out.println();
System.out.println("二进制中1的个数(1):"+Count1(x));
System.out.println("二进制中1的个数(2):"+Count2(x));
System.out.println("二进制中1的个数(3):"+Count3(x));
}
}
public class c2_1 { public static int Count1(int x){ int num=0; while(x!=0){ if( x%2 == 1 ) num++; x/=2; } return num; } public static int Count2(int x){...