思路
任何数和1进行与操作,都保留其末尾数
private static void oneCount(int i) { int count = 0; while (i > 0) { int one = i & 1; if (one == 1) { count++; } i = i >> 1; } System.out.println(":count:" + count); }
思路
任何数和1进行与操作,都保留其末尾数
private static void oneCount(int i) { int count = 0; while (i > 0) { int one = i & 1; if (one == 1) { count++; } i = i >> 1; } System.out.println(":count:" + count); }