File size: 269 Bytes
c574d3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public class BitCounting {
public static int countBits(int n) {
String bBits = Integer.toBinaryString(n);
int count = 0;
for (String b : bBits.split("")) {
if (Integer.valueOf(b) == 1) {
count++;
}
}
return count;
}
} |