C#操作Byte数组和十六进制进行互转

2022-05-05 11:01:43

一、Byte> /// <summary> /// Byte 数组转十六进制字符串 /// </summary> /// <param name="Bytes"></param> /// <returns></returns> public static string ByteToHex(byte[] Bytes) { string str = string.Empty; foreach (byte Byte in Bytes) { str += String.Format("{0:X2}", Byte) + " "; } return str.Trim(); }

二、字符串转十六进制Byte数组

>www.easck.comtring.Length % 2) != 0) hexString += " "; byte[] returnBytes = new byte[hehttp://www.easck.comxString.Length / 2]; for (int i = 0; i < returhttp://www.easck.comnBytes.Length; i++) returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16); return returnBytes; } catch { return null; } }

到此这篇关于C#操作Byte数组和十六进制进行互转的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持我们。