Here you can find the source of bitSetToByteArray(BitSet bitSet, int bitSetLength)
private static byte[] bitSetToByteArray(BitSet bitSet, int bitSetLength)
//package com.java2s; //License from project: Open Source License import java.util.BitSet; public class Main { private static byte[] bitSetToByteArray(BitSet bitSet, int bitSetLength) { byte[] ret = bitSet.toByteArray(); if (ret.length == bitSetLength) { return ret; }/* ww w .jav a2 s . co m*/ byte[] finalRet = new byte[bitSetLength % 8 == 0 ? bitSetLength / 8 : bitSetLength / 8 + 1]; System.arraycopy(ret, 0, finalRet, 0, ret.length); return finalRet; } }