/**
* Convert a booleans array to bytes array.
*
* @param booleans
* The array to convert.
* @return A bytes array from booleans array.
*/
private byte[] booleans2bytes(boolean[] booleans) {
byte[] bytes = new byte[booleans.length / 8];
for (int iB = 0; iB < bytes.length; iB++) {
byte B = 0;
for (int i = 1; i < 8; i++) {
int bToi = booleans[iB * 8 + i] ? 1 : 0;
B += (byte) (Math.abs(bToi * Math.pow(2, 8 - i - 1)));
}
if (booleans[iB * 8])
bytes[iB] = (byte) (128 + B);
else
bytes[iB] = B;
}
return bytes;
}