public byte[] BooleansToByteArray(bool[] tBool) {
int BLenght = (int)System.Math.Ceiling((double)tBool.Length / 8.0);
byte[] tB = new byte[BLenght];
for (int iBool = 0, iB = 0; iBool < tBool.Length; iBool += 8, iB++) {
byte B = 0;
for (int i = 0; i < 8; i++)
if (iBool + i < tBool.Length)
B += (byte)(System.Math.Abs(System.Convert.ToInt32(tBool[iBool + i]) * System.Math.Pow(2, i)));
tB[iB] = B;
}
return tB;
}