Java examples for java.util:BitSet
Returns the number of bits set to true in the bitset.
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { int bitset = 2; System.out.println(cardinality(bitset)); }// www . j a v a 2 s .co m /** * Returns the number of bits set to <tt>true</tt> in the bitset. * * @param bitset * the bitset. * @return the number of bits set to <tt>true</tt> in the bitset. */ public static int cardinality(int bitset) { return Integer.bitCount(bitset); } }