To get long back from small BitSet in BitSet :
long l = bitSet.stream() .takeWhile(i -> i < Long.SIZE) .mapToLong(i -> 1L << i) .reduce(0, (a, b) -> a | b);
And vice versa:
BitSet bitSet = IntStream.range(0, Long.SIZE - 1) .filter(i -> 0 != (l & 1L << i)) .collect(BitSet::new, BitSet::set, BitSet::or);
NB: Using BitSet::valueOf and BitSet::toLongArray is certainly simpler.
charlie Jul 04 '16 at 13:17 2016-07-04 13:17
source share