Public Function BooleansToByteArray(ByVal tBool() As Boolean) As Byte()
Dim BLength As Integer = CInt(System.Math.Ceiling(tBool.Length / 8))
Dim tB() As Byte = CType(System.Array.CreateInstance(GetType(Byte), BLength), Byte())
Dim iB As Integer = 0
For iBool As Integer = 0 To tBool.Length - 1 Step 8
Dim B As Byte = 0
For i As Integer = 0 To 7
If iBool + i < tBool.Length Then
B += CByte(System.Math.Abs(CInt(tBool(iBool + i))) * CInt(System.Math.Pow(2, i)))
End If
Next i
tB(iB) = B
iB += 1
Next iBool
Return tB
End Function