C#中16进制string字符串的转16byte互转
贴⼀个到的现成16进制互转⽅法
⾸先先来看数据源
C1 C1 1711 2B 0008 D9 6B 300100010000 1E 848013880000000000000003000100 0F 424000000055010100000000000000000000这是⼀个16进制的字符串,具体怎么切割操作就不说了,直接上转换代码
byte.Parse(
      tempArray[i],
System.Globalization.NumberStyles.HexNumber,
System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
上⾯那个⽅法好像有点点问题,⼜了⼀个能⽤的,放这⾥
private static byte[] strToToHexByte(string hexString)
{
hexString = hexString.Replace("", "");
if ((hexString.Length % 2) != 0)
hexString += "";
byte[] returnBytes = new byte[hexString.Length / 2];
for (int i = 0; i < returnBytes.Length; i++)
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
return returnBytes;
}
字符串数组怎么转成byte这样就可以了
那么16进制byte[] 转回字符串呢?
string hex = BitConverter.ToString(tempBytes, 0, tempBytes.Length).Replace("-", string.Empty);
结束

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。