Here you can find the source of bytesToBits(byte[] b, BitSet ba, int maxSize)
Parameter | Description |
---|---|
b | the byte[] to read from |
ba | the bitset to write to |
public static void bytesToBits(byte[] b, BitSet ba, int maxSize)
//package com.java2s; /*//ww w .ja va2 s . c o m * JGrass - Free Open Source Java GIS http://www.jgrass.org * (C) HydroloGIS - www.hydrologis.com * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Library General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) any * later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more * details. * * You should have received a copy of the GNU Library General Public License * along with this library; if not, write to the Free Foundation, Inc., 59 * Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.util.BitSet; public class Main { /** * Read bits from a byte array into a bitset * @param b the byte[] to read from * @param ba the bitset to write to */ public static void bytesToBits(byte[] b, BitSet ba, int maxSize) { int x = 0; for (int i = 0; i < b.length; i++) { for (int j = 0; j < 8; j++) { if (x > maxSize) break; int mask = 1 << j; boolean value = (mask & b[i]) != 0; ba.set(x, value); x++; } } } }