Here you can find the source of toBitSet(byte[] bytes)
Parameter | Description |
---|---|
bytes | The byte array to be converted into a bit set |
public static BitSet toBitSet(byte[] bytes)
//package com.java2s; //License from project: Open Source License import java.util.BitSet; public class Main { /**//from w ww . j a v a 2s . c om * Convert a byte array into a bit set. * * @param bytes The byte array to be converted into a bit set * @return The equivalent bit set */ public static BitSet toBitSet(byte[] bytes) { BitSet bs = new BitSet(); for (int i = 0; i < bytes.length * 8; i++) { if ((bytes[i / 8] & (1 << (7 - (i % 8)))) > 0) bs.set(i, true); else bs.set(i, false); } return bs; } }