Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,914 questions

51,847 answers

573 users

How to convert binary digits to a byte list in VB.NET

1 Answer

0 votes
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 
'

 



answered Aug 4, 2025 by avibootz
edited Aug 6, 2025 by avibootz
...