Here you can find the source of toByteArray(BitSet bits, int sizeInBytes)
public static byte[] toByteArray(BitSet bits, int sizeInBytes)
//package com.java2s; //License from project: Minecraft Mod Public import java.util.BitSet; public class Main { public static byte[] toByteArray(BitSet bits) { return toByteArray(bits, (bits.size() + 7) >> 3); }/* ww w. j a v a 2 s . c om*/ public static byte[] toByteArray(BitSet bits, int sizeInBytes) { byte[] bytes = new byte[sizeInBytes]; for (int i = 0; i < bits.length(); i++) { if (bits.get(i)) { bytes[i / 8] |= 1 << (i % 8); } } return bytes; } }