How to print byte array in VB.NET

5 Answers

0 votes
Imports System
Imports System.Text

Public Class Program
    Public Shared Sub PrintByteArray(ByVal bytes As Byte())
        Dim sb = New StringBuilder("byte[] = ")
        Dim b

        For Each b In bytes
            sb.Append(b & ", ")
        Next

        Console.WriteLine(sb.ToString())
    End Sub

    Public Shared Sub Main()
        Dim bytes As Byte() = New Byte() {1, 2, 4, 16, 32, 64, 128}
        
        PrintByteArray(bytes)
    End Sub
End Class




' run:
'
' byte[] = 1, 2, 4, 16, 32, 64, 128, 
'


 



answered May 28, 2024 by avibootz
0 votes
Imports System
Imports System.Text

Public Class Program
    Public Shared Sub Main()
        Dim bytes As Byte() = New Byte() {97, 98, 122}
        
        Console.WriteLine(Encoding.UTF8.GetString(bytes))

    End Sub
End Class




' run:
'
' abz
'

 



answered May 28, 2024 by avibootz
0 votes
Imports System

Public Class Program
	Public Shared Sub Main()
        Dim bytes As Byte() = New Byte() {1, 2, 4, 16, 32, 64, 128}
		
        Console.WriteLine(String.Join(", ", bytes))
    End Sub
End Class
   
   
' run:
'
' 1, 2, 4, 16, 32, 64, 128
'

 



answered Jun 20, 2024 by avibootz
0 votes
Imports System

Public Class Program
    Public Shared Sub PrintByteArray(ByVal barray As Byte())
        Console.Write("byte[] = ")

        For Each b As Byte In barray
            Console.Write(b.ToString() & " ")
        Next

        Console.WriteLine()
    End Sub

    Public Shared Sub Main(ByVal args As String())
        Dim barr As Byte() = New Byte() {1, 2, 4, 16, 32, 64, 128}
        PrintByteArray(barr)
    End Sub
End Class

   
   
' run:
'
' byte[] = 1 2 4 16 32 64 128
'

 



answered Jun 20, 2024 by avibootz
0 votes
Imports System

Public Class Program
    Public Shared Sub PrintByteArray(ByVal barray As Byte())
        Console.Write("byte[] = ")

        For Each b As Byte In barray
            Console.Write(b.ToString("X2") & " ")
        Next

        Console.WriteLine()
    End Sub

    Public Shared Sub Main(ByVal args As String())
        Dim barr As Byte() = New Byte() {1, 2, 4, 16, 32, 64, 128, 255}
	
        PrintByteArray(barr)
    End Sub
End Class

   
   
' run:
'
' byte[] = 01 02 04 10 20 40 80 FF
'

 



answered Jun 20, 2024 by avibootz

Related questions

3 answers 259 views
259 views asked Jan 20, 2021 by avibootz
2 answers 107 views
2 answers 160 views
2 answers 208 views
2 answers 204 views
1 answer 156 views
1 answer 155 views
...