Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 Eclipse RDF4J contributors, Aduna, and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Distribution License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/org/documents/edl-v10.php. *******************************************************************************/ 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)); } }