public static void getNumOfOneInBinery() {
int targetIntValue0 = 10;//1010
int targetIntValue1 = 11;//1011
int targetIntValue2 = 13;//1110
getOneNum(targetIntValue0);
getOneNum(targetIntValue1);
getOneNum(targetIntValue2);
}
public static void getOneNum(int target) {
int origin = target;
int count = 0;
while (target > 0) {
if ((target & 1) == 1) {
count++;
}
target = target >> 1;
}
System.out.println("getNumOfOneInBinery target="+origin+"--num = "+count);
}
12-14 11:45:17.112 22385-22385/? I/System.out: getNumOfOneInBinery target=10--num = 2
12-14 11:45:17.112 22385-22385/? I/System.out: getNumOfOneInBinery target=11--num = 3
12-14 11:45:17.112 22385-22385/? I/System.out: getNumOfOneInBinery target=13--num = 3