List of utility methods to do BitSet Create
BitSet | bitSet(byte[] bytes) Create a BitSet instance,start index is 0 example: byte: 50 binary: 0b110010 +--------+---+---+---+---+---+---+---+---+ | bits | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | +--------+---+---+---+---+---+---+---+---+ | bitset | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +--------+---+---+---+---+---+---+-------+ bitSet.toString(): {2, 3, 6} if (bytes == null) { return null; BitSet bit = new BitSet(); int index = 0; for (byte aByte : bytes) { for (int j = 7; j >= 0; j--) { bit.set(index++, (aByte & (1 << j)) >>> j == 1); ... |
BitSet | bitSet(byte[] bytes) Create a BitSet instance,start index is 0. if (bytes == null) { throw new IllegalArgumentException("bitMap must not be null"); BitSet bit = new BitSet(); int index = 0; for (int i = 0; i < bytes.length; i++) { for (int j = 7; j >= 0; j--) { bit.set(index++, (bytes[i] & (1 << j)) >>> j == 1); ... |
BitSet | bitSet(String string) bit Set BitSet result = new BitSet(); for (int i = string.length(); --i >= 0;) result.set(string.charAt(i)); return result; |
BitSet | bitSetFrom(long number) Creates a BitSet representation of a given long return bitSetFrom(number, NBITS_LONG_REPRESENTATION);
|
BitSet | bitsetFromIndices(int size, int... indices) Constructs a new BitSet of given size whose set bits are specified by indices . final BitSet bitset = new BitSet(size); for (int index : indices) { if (index < 0 || index >= size) { throw new IndexOutOfBoundsException( String.format("Index %d out of range [0, %d]", index, size - 1)); if (bitset.get(index)) { throw new IllegalArgumentException(String.format("Duplicate index %d", index)); ... |
BitSet | bitsetFromString(String pixelsString) bitset From String BitSet pixels = new BitSet(pixelsString.length()); int index = 0; for (int i = 0; i < pixelsString.length(); i++) { char c = pixelsString.charAt(i); if (c == '\n') { continue; pixels.set(index, c != '0'); ... |
BitSet | bitSetOf(long lowerBits, long upperBits) bit Set Of final BitSet bitSet = new BitSet(); convert(lowerBits, 0, bitSet); convert(upperBits, Long.SIZE, bitSet); return bitSet; |
BitSet | bitSetOf(String inString) bit Set Of BitSet bitSet = new BitSet(); int i = 0; for (byte b : inString.getBytes()) { if (b == '1') { bitSet.set(i); i += 1; return bitSet; |
BitSet | bitSetOfIndexes(int... indexes) bit Set Of Indexes BitSet bitSet = new BitSet(); for (int index : indexes) { bitSet.set(index); return bitSet; |
BitSet | Byte2BitSet(byte bytes) Byte Bit Set BitSet bits = new BitSet(8); for (int i = 0; i < 8; i++) { if ((bytes & (1 << i)) > 0) { bits.set(i); return bits; |