List of utility methods to do BitSet Convert
byte[] | bitSet2byte(BitSet b) converts a BitSet into a binary field used in pack routines This method will set bits 0 (and 65) if there's a secondary (and tertiary) bitmap (i.e., if the bitmap length is > 64 (and > 128)) int len = b.length() + 62 >> 6 << 6; byte[] d = new byte[len >> 3]; for (int i = 0; i < len; i++) if (b.get(i + 1)) d[i >> 3] |= 0x80 >> i % 8; if (len > 64) d[0] |= 0x80; if (len > 128) ... |
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; ... |
String | bitSet2String(BitSet b) bit representation of a BitSet suitable for dumps and debugging int len = b.size(); len = len > 128 ? 128 : len; StringBuilder d = new StringBuilder(len); for (int i = 0; i < len; i++) d.append(b.get(i) ? '1' : '0'); return d.toString(); |