Here you can find the source of longFrom(final BitSet bitSet)
Parameter | Description |
---|---|
bitSet | the bitset |
public static long longFrom(final BitSet bitSet)
//package com.java2s; //License from project: Apache License import java.util.BitSet; public class Main { static final private byte NBITS_LONG_REPRESENTATION = 64; /**//ww w . j a va 2s . c om * Creates an long out of a bitset * * @param bitSet the bitset * @return a long from the bitset representation */ public static long longFrom(final BitSet bitSet) { return longFrom(bitSet, NBITS_LONG_REPRESENTATION); } /** * Cretes an integer with any number of bits (up to 64 -- long precision) from a bitset * * @param bitSet the bitset * @param nBits the number of bits to be used for this representation * @return an integer with nBits from the bitset representation */ public static long longFrom(final BitSet bitSet, final int nBits) { long number = 0; for (int bitIndex = bitSet.nextSetBit(0); bitIndex >= 0 && bitIndex <= nBits; bitIndex = bitSet.nextSetBit(bitIndex + 1)) number |= 1L << bitIndex; return number; } }