字符串转十六进制数组

举个例子:

字符串:str_Command=“01 06 10 00 00 00 8D 07”

转为8位字节数组:

string[] strs = str_Command.Split(' ');
byte[] bts = new byte[strs.Length];

for (int i = 0; i < strs.Length; i++)
{
bts[i] = byte.Parse(strs[i], System.Globalization.NumberStyles.HexNumber);
}

//思路:

1.字符串转字符串数组,

2.遍历字符串数组,通过Byte.Parse(),获取字节数组。

 

posted @ 2022-06-23 09:29  冲云霄  阅读(367)  评论(0)    收藏  举报