Java BitSet to convert(BitSet bits)

Here you can find the source of convert(BitSet bits)

Description

convert

License

Open Source License

Declaration

public static long convert(BitSet bits) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.BitSet;

public class Main {
    public static BitSet convert(long value) {
        BitSet bits = new BitSet();
        int index = 0;
        while (value != 0L) {
            if (value % 2L != 0) {
                bits.set(index);/*from w  w  w.j  a  v a  2 s . c  om*/
            }
            ++index;
            value = value >>> 1;
        }
        return bits;
    }

    public static long convert(BitSet bits) {
        long value = 0L;
        for (int i = 0; i < bits.length(); ++i) {
            value += bits.get(i) ? (1L << i) : 0L;
        }
        return value;
    }
}

Related

  1. bitsToBytes(BitSet ba, int size)
  2. BitsToBytes(BitSet bits)
  3. bitsToHexString(BitSet ba, int size)
  4. BitsToInt(BitSet bits, int length)
  5. convert(BitSet bits)