Hexadecimal 8 bit unsigned array in VB.NET

I have a hexadecimal value,

07A5953EE7592CE8871EE287F9C0A5FBC2BB43695589D95E76A4A9D37019C8

What I want to convert to a byte array.

Is there a built-in function in .NET 3.5 that will do the job, or will I need to write a function to loop through each pair in a string and convert it to its 8-bit integer equivalent?

+2


source to share


2 answers


There is no built-in function to do this. You unfortunately have to code one :(

Public Function ToHexList(ByVal str As String) As List(Of Byte) 
  Dim list As New List(Of Byte)
  For i = 0 to str.Length-1 Step 2
    list.Add(Byte.Parse(str.SubString(i,2), Globalization.NumberStyles.HexNumber))
  Next
  Return list
End Function

      



EDIT

The NumberStyles enumeration qualified with a globalization namespace qualifier. Another option is to import this namespace and remove the qualifier.

+2


source


I think you will find what you are looking for here (codeproject.com)



0


source







All Articles