BitSetMath { public static long littleEndianBitSetToNonNegativeLong(BitSet bs) { Preconditions.checkArgument(bs.length() < 64, "too many bits"); long value = 0; for (int i = bs.nextSetBit(0); i != -1; i = bs.nextSetBit(i + 1)) { value |= 1L << i; } assert value >= 0; assert Long.bitCount(value) == bs.cardinality() : "Wrong cardinality for " + bs; return value; } private  BitSetMath(); static int increment(BitSet i); static void rotate(BitSet bs, int n, int count); static void extractBitRange(BitSet chi, int from, int to, BitSet r); static void grayCode(BitSet i); static void grayCodeInverse(BitSet i); static void copy(BitSet from, BitSet to); static long littleEndianBitSetToNonNegativeLong(BitSet bs); static void nonNegativeLongToLittleEndianBitSet(long value, BitSet bs);  }
@Test public void littleEndianBitSetToNonNegativeLong() { for (int i = 0; i < 1024; ++i) { BitSet bs = TestUtils.unsignedIntToLittleEndianBitSet(i); long bigInt = BitSetMath.littleEndianBitSetToNonNegativeLong(bs); Assert.assertEquals(i, bigInt); } }