Imports System
Imports System.Collections.Generic
Class BinaryConverter
Public Shared Function BinaryToByteList(ByVal binaryString As String) As List(Of Byte)
Dim byteList = New List(Of Byte)()
If binaryString.Length Mod 8 <> 0 Then
Throw New ArgumentException("Binary string length must be a multiple of 8.")
End If
For i As Integer = 0 To binaryString.Length - 1 Step 8
Dim byteString As String = binaryString.Substring(i, 8)
Dim byteValue As Byte = Convert.ToByte(byteString, 2)
byteList.Add(byteValue)
Next
Return byteList
End Function
Public Shared Sub Main()
Dim binaryString As String = "10101110111010101110101001001011"
Try
Dim byteList As List(Of Byte) = BinaryToByteList(binaryString)
Console.Write("Byte List: ")
For Each b As Byte In byteList
Console.Write($"{b} ")
Next
Console.WriteLine()
Catch e As Exception
Console.Error.WriteLine($"Error: {e.Message}")
End Try
End Sub
End Class
' run:
'
' Byte List: 174 234 234 75
'