Java Utililty Methods BitSet

List of utility methods to do BitSet

Description

The list of methods to do BitSet are organized into topic(s).

Method

BitSethex2BitSet(byte[] b, int offset, int maxBits)
Converts an ASCII representation of a Bitmap field into a Java BitSet
int len = maxBits > 64 ? ((Character.digit((char) b[offset], 16) & 0x08) == 8 ? 128 : 64) : maxBits;
BitSet bmap = new BitSet(len);
for (int i = 0; i < len; i++) {
    int digit = Character.digit((char) b[offset + (i >> 2)], 16);
    if ((digit & (0x08 >> (i % 4))) > 0) {
        bmap.set(i + 1);
        if (i == 65 && maxBits > 128)
            len = 192;
...
voidhexToBits(String s, BitSet ba, int length)
Read a hex string of bits and write it into a bitset
byte[] b = hexToBytes(s);
bytesToBits(b, ba, length);
booleanincrement(BitSet bits, int size)
increment
int i = size - 1;
while (i >= 0 && bits.get(i)) {
    bits.set(i--, false);
if (i < 0) {
    return false;
bits.set(i, true);
...
BitSetinsertBits(BitSet fromSet, int insertBefore, int count)
Insert a range of bit positions into a BitSet.
BitSet newSet = new BitSet(fromSet.size() + count);
for (int i = 0; i < insertBefore; i++) {
    if (fromSet.get(i))
        newSet.set(i);
for (int i = insertBefore; i < fromSet.size(); i++) {
    if (fromSet.get(i))
        newSet.set(i + count);
...
BitSetintArrToBitSet(ArrayList integerArray)
Convert an 'ArrayList' of 'Integer' objects to a BitSet
if (integerArray == null)
    return null;
BitSet bitSet = new BitSet();
for (Iterator iter = integerArray.iterator(); iter.hasNext();) {
    bitSet.set(((Integer) iter.next()).intValue());
return bitSet;
BitSetintToBitSet(int value)
Convert an integer to BitSet.
BitSet bits = new BitSet();
int index = 0;
while (value != 0) {
    if (value % 2 != 0) {
        bits.set(index);
    ++index;
    value = value >>> 1;
...
BitSetinvertInPlace(BitSet bs, int n)
inverts the bitset bits 0 through n-1, and returns a reference to the modified bitset
return copy(copyInvert(bs, n), bs);
booleanisEmptySet(BitSet setToTest)
Test if the given set is empty
return setToTest.equals(EMPTY_BIT_SET);
booleanisHammingDistanceOne(BitSet a, BitSet b)
is Hamming Distance One
int distance = 0;
int i = 0;
while (i < a.size()) {
    if (a.get(i) != b.get(i)) {
        distance++;
    i++;
    if (distance > 1) {
...
booleanisSet(int n, BitSet... sets)
is Set
if (n == -1)
    return false;
BitSet set = new BitSet();
for (BitSet s : sets)
    set.or(s);
return set.get(n);