Java examples for java.lang:Math Number
count Number Bits
//package com.java2s; public class Main { public static int countNumBits(int N) { int v = N; // count the number of bits set in v int c; // c accumulates the total bits set in v for (c = 0; v != 0; c++) { v &= v - 1; // clear the least significant bit set }/*from w w w . j a v a2 s . co m*/ return c; } }