Converts the {@link BitSet} {@code bits} into a long value.
<p>
This is the reverse operation from {@link #toBitSet(int, long)}.
338063
public static final long fromBitSet(final BitSet bits) {
    long value = 0L;
    for (int i = 0; i < bits.size(); i++) {
      value += bits.get(i) ? (1L << i) : 0L;
    }
    return value;
  }
471100
public static Collection<Integer> ofSetBits(long i) {
    	final Collection<Integer> c = new LinkedList<Integer>();
        int k = 0;
        while (i != 0) {
            if ((i & 1L) != 0) {
                c.add(k);
            }
            k++;
            i >>>= 1;
        }
        return c;
    }
747895
public static int d(BitSet x, BitSet y) {
        if (x.size() != y.size())
            throw new IllegalArgumentException(String.format("BitSets have different length: x[%d], y[%d]", x.size(), y.size()));

        int dist = 0;
        for (int i = 0; i < x.size(); i++) {
            if (x.get(i) != y.get(i))
                dist++;
        }

        return dist;
    }
617773
private static BitSet validCookieAttributeValueOctets() {
        BitSet bits = new BitSet();
        for (int i = 32; i < 127; i++) {
            bits.set(i);
        }
        bits.set(';', false);
        return bits;
    }
468057
public long nextLong(final long n) 
        {
        if (n<=0)
            throw new IllegalArgumentException("n must be > 0");
        
        long bits, val;
        do 
            {
            bits = (nextLong() >>> 1);
            val = bits % n;
            } 
        while(bits - val + (n-1) < 0);
        return val;
        }
1050340
static long readBits(ReadStream reader, int count) {
		long bits = 0L;
		for (int i = (count - 1) >> 3; i >= 0; i --) {
			bits <<= 8;
			bits |= reader.readByte() & 0xff;
		}
		return bits;
	}
1122102
public static String toHexString(final BitSet set) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        PrintWriter writer = new PrintWriter(out);
        final long[] longs = set.toLongArray();
        for (long aLong : longs) {
            writer.write(Long.toHexString(aLong));
        }
        writer.flush();

        return new String(out.toByteArray(), java.nio.charset.StandardCharsets.UTF_8);
    }
469147
public static long toLongValue(String str) throws PageException {
	BigInteger bi = null;
	try {
	    bi = new BigInteger(str);

	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	}
	if (bi != null) {
	    if (bi.bitLength() < 64) return bi.longValue();
	    throw new ApplicationException("number [" + str + "] cannot be casted to a long value, number is to long (" + (bi.bitLength() + 1) + " bit)");
	}
	return (long) toDoubleValue(str);
    }
1081945
public Bits encode(final T key) {
    final Bits bits = this.reverseIndex.get(key);
    assert null != bits || this.verifyIndexes();
    return bits;
  }
521820
public void writeBit(final int bit)
		throws EncodingException
	{

		if (bit != 0 && bit != 1) {
			throw ErrorFactory.createEncodingException(
					ErrorKeys.DIFFTOOL_ENCODING_VALUE_OUT_OF_RANGE,
					"bit value out of range: " + bit);
		}

		this.buffer |= bit << (7 - this.bufferLength);
		this.bufferLength++;

		if (bufferLength == 8) {

			write(buffer);

			this.bufferLength = 0;
			this.buffer = 0;
		}
	}
382964
public static Collection<Integer> ofUnsetBits(long i) {
    	final Collection<Integer> c = new LinkedList<Integer>();
        int k = 0;
        while (i != 0) {
            if ((i & 1L) == 0) {
                c.add(k);
            }
            k++;
            i >>>= 1;
        }
        return c;
    }
1124878
private static byte[] convertBits(final byte[] in, final int inStart, final int inLen, final int fromBits,
            final int toBits, final boolean pad) throws AddressFormatException {
        int acc = 0;
        int bits = 0;
        ByteArrayOutputStream out = new ByteArrayOutputStream(64);
        final int maxv = (1 << toBits) - 1;
        final int max_acc = (1 << (fromBits + toBits - 1)) - 1;
        for (int i = 0; i < inLen; i++) {
            int value = in[i + inStart] & 0xff;
            if ((value >>> fromBits) != 0) {
                throw new AddressFormatException(
                        String.format("Input value '%X' exceeds '%d' bit size", value, fromBits));
            }
            acc = ((acc << fromBits) | value) & max_acc;
            bits += fromBits;
            while (bits >= toBits) {
                bits -= toBits;
                out.write((acc >>> bits) & maxv);
            }
        }
        if (pad) {
            if (bits > 0)
                out.write((acc << (toBits - bits)) & maxv);
        } else if (bits >= fromBits || ((acc << (toBits - bits)) & maxv) != 0) {
            throw new AddressFormatException("Could not convert bits, invalid padding");
        }
        return out.toByteArray();
    }
531729
@VisibleForTesting
    static double longToDoubleFraction(long value) {
        long shifted = (value >> 12) & MASK;
        return Double.longBitsToDouble(LEADING_BITS + shifted) - 1;
    }
978519
private long toLong() {
        assert (intLen <= 2) : "this MutableBigInteger exceeds the range of long";
        if (intLen == 0)
            return 0;
        long d = value[offset] & LONG_MASK;
        return (intLen == 2) ? d << 32 | (value[offset + 1] & LONG_MASK) : d;
    }
1022072
private BitSet toBitSet(int[] mapping) {
        BitSet hits = new BitSet();
        for (int v : mapping)
            hits.set(v);
        return hits;
    }
1208949
public static int longToInt(long inLong) {

        if (inLong < Integer.MIN_VALUE) {
            return Integer.MIN_VALUE;
        }

        if (inLong > Integer.MAX_VALUE) {
            return Integer.MAX_VALUE;
        }

        return (int) inLong;
    }
26252
public static long toLong(byte[] b, int off, boolean littleEndian) {
		if (littleEndian) {
			return (toInt(b, off, LITTLE_ENDIAN) & 0xFFFFFFFFL) |
					((toInt(b, off + 4, LITTLE_ENDIAN) & 0xFFFFFFFFL) << 32);
		}
		return ((toInt(b, off, BIG_ENDIAN) & 0xFFFFFFFFL) << 32) |
				(toInt(b, off + 4, BIG_ENDIAN) & 0xFFFFFFFFL);
	}