VB.NET中的十六进制到8位无符号数组 [英] Hexadecimal to 8-bit unsigned array in VB.NET

查看:306
本文介绍了VB.NET中的十六进制到8位无符号数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个十六进制值,


07A5953EE7592CE8871EE287F9C0A5FBC2BB43695589D95E76A4A9D37019C8

我想转换为一个字节数组。



.NET 3.5中有一个内置函数可以完成工作吗?需要编写一个函数来循环每个字符串中的每一对,并将其转换为它的8位整数等价?

没有内置的功能可以做到这一点。你将不得不编码一个:($ / $>

  Public Function ToHexList(ByVal str As String)As List(Of Byte)
Dim list As New List(Byte)
For i = 0 to str.Length-1 Step 2
list.Add(Byte.Parse(str.SubString(i,2),Globalization .NumberStyles.HexNumber))
下一个
返回列表
结束函数

编辑



使用Globalization名称空间限定符限定NumberStyles枚举。另一个选项是导入该名称空间并删除限定符。 >

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?

解决方案

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.

这篇关于VB.NET中的十六进制到8位无符号数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆