List of utility methods to do BitSet to
String | Bitset2BitString(BitSet bitset, int length) Converts the given BitSet to a {0,1}-String of the given length. if (bitset.size() < length) { throw new IllegalArgumentException("length if longer than the bitset lenght"); StringBuilder builder = new StringBuilder(length); for (int i = length - 1; i >= 0; i--) { if (bitset.get(i)) { builder.append("1"); } else { ... |
byte[] | bitSet2byte(BitSet b, int bytes) converts a BitSet into a binary field used in pack routines int len = bytes * 8; byte[] d = new byte[bytes]; for (int i = 0; i < len; i++) { if (b.get(i + 1)) { d[i >> 3] |= (0x80 >> (i % 8)); if (len > 64) { ... |
byte | bitset2bytes(BitSet bits, byte[] bytes) bitsetbytes byte nbyte = (byte) (bits.length() / 8 + 1); if (bytes.length < nbyte) { bytes = new byte[nbyte]; for (int i = 0; i < bits.length(); i++) { if (bits.get(i)) { bytes[nbyte - i / 8 - 1] |= 1 << (i % 8); return nbyte; |
byte[] | bitSet2extendedByte(BitSet b) Converts a BitSet into an extended binary field used in pack routines. int len = 128; byte[] d = new byte[len >> 3]; for (int i = 0; i < len; i++) if (b.get(i + 1)) d[i >> 3] |= (0x80 >> (i % 8)); d[0] |= 0x80; return d; |
int | bitSet2Int(BitSet bs) bit Set Int int total = 0; int b = bs.length() - 1; if (b > 0) { int value = (int) Math.pow(2, b); for (int i = 0; i <= b; i++) { if (bs.get(i)) total += value; value = value >> 1; ... |
double[] | bitsetToDoubleArray(BitSet bs, int n) Create an n-element array of doubles (0s and 1s) from a BitSet. int i; double res[] = new double[n]; for (i = 0; i < n; i++) res[i] = bs.get(i) ? 1.0 : 0.0; return res; |
int[] | bitsetToIndices(BitSet bits) Returns a newly constructed array containing the indices of the non-zero bits. final int[] indices = new int[bits.cardinality()]; for (int i = 0, index = -1, end = indices.length; i < end; ++i) { index = bits.nextSetBit(++index); indices[i] = index; return indices; |
int | bitSetToInt(final BitSet bitSet) Gets the integer value from a given Bitset. int bitInteger = 0; for (int i = 0; i < 32; i++) { if (bitSet.get(i)) { bitInteger |= 1 << i; return bitInteger; |
long | bitSetToLong(BitSet set) bit Set To Long int max = set.length(); long bits = 0; for (int count = 0; count < max; count++) { if (set.get(count)) bits |= (1L << count); return bits; |
Map | bitSetToMap(Map Stores a BitSet object as a string in a map. map.put(key, bitSetToString(bits, length));
return map;
|