Here you can find the source of byte2BitSet(byte[] b, int offset, int maxBits)
Parameter | Description |
---|---|
b | - binary representation |
offset | - staring offset |
maxBits | - max number of bits (supports 64,128 or 192) |
public static BitSet byte2BitSet(byte[] b, int offset, int maxBits)
//package com.java2s; import java.util.BitSet; public class Main { /**//from w w w . j a v a 2s. c o m * Converts a binary representation of a Bitmap field into a Java BitSet * * @param b - binary representation * @param offset - staring offset * @param maxBits - max number of bits (supports 64,128 or 192) * @return java BitSet object */ public static BitSet byte2BitSet(byte[] b, int offset, int maxBits) { int len = maxBits > 64 ? ((b[offset] & 0x80) == 0x80 ? 128 : 64) : maxBits; if (maxBits > 128 && b.length > offset + 8 && (b[offset + 8] & 0x80) == 0x80) { len = 192; } BitSet bmap = new BitSet(len); for (int i = 0; i < len; i++) { if (((b[offset + (i >> 3)]) & (0x80 >> (i % 8))) > 0) { bmap.set(i + 1); } } return bmap; } }