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 byte array to a hex string in VB.NET

2 Answers

0 votes
Imports System

Public Class Program
    Public Shared Sub Main()
        Dim bytes As Byte() = {0, 1, 2, 3, 4, 5, 10, 20, 254, 255}
        
        Dim hexString As String = BitConverter.ToString(bytes).Replace("-", " ")
        
        Console.WriteLine(hexString)
    End Sub
End Class




' run:
'
' 00 01 02 03 04 05 0A 14 FE FF
'

 



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

Public Class Program
    Public Shared Function ByteArrayToString(ByVal ba As Byte()) As String
        Dim hex As StringBuilder = New StringBuilder(ba.Length * 2)

        For Each b As Byte In ba
            hex.AppendFormat("{0:X2} ", b)
        Next

        Return hex.ToString()
    End Function

    Public Shared Sub Main()
        Dim bytes As Byte() = {0, 1, 2, 3, 4, 5, 10, 20, 254, 255}
        
        Dim hexString As String = ByteArrayToString(bytes)
        
        Console.WriteLine(hexString)
    End Sub
End Class




' run:
'
' 00 01 02 03 04 05 0A 14 FE FF 
'


 



answered May 27, 2024 by avibootz

Related questions

2 answers 179 views
1 answer 169 views
169 views asked Jan 21, 2021 by avibootz
1 answer 421 views
1 answer 191 views
1 answer 180 views
180 views asked Jan 21, 2021 by avibootz
1 answer 247 views
1 answer 151 views
...