Hexadecimal to 8-bit unsigned array in VB.NET

冷暖自知 提交于 2019-12-24 00:25:23

问题


I have a hexadecimal value,

07A5953EE7592CE8871EE287F9C0A5FBC2BB43695589D95E76A4A9D37019C8

Which I want to convert to a byte array.

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


回答1:


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

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

Qualified the NumberStyles enumeration with the Globalization namespace qualifier. Another option is to import that namespace and remove the qualifier.




回答2:


I think that you'll find what you are looking for here (codeproject.com)



来源:https://stackoverflow.com/questions/1335700/hexadecimal-to-8-bit-unsigned-array-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!