Here you can find the source of toBitSet(byte[] array)
public static BitSet toBitSet(byte[] array)
//package com.java2s; /*//from www. j a v a 2 s. c o m * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006. * * Licensed under the Aduna BSD-style license. */ import java.util.BitSet; public class Main { public static BitSet toBitSet(byte[] array) { BitSet bitSet = new BitSet(8 * array.length); for (int byteNo = 0; byteNo < array.length; byteNo++) { byte b = array[byteNo]; for (int bitNo = 0; bitNo < 8; bitNo++) { if ((b & byteMask(bitNo)) != 0) { bitSet.set(8 * byteNo + bitNo); } } } return bitSet; } private static byte byteMask(int bitNo) { return (byte) (0x80 >>> (bitNo % 8)); } }