C#16进制字符串转为byte数组,byte数组转换为16进制字符串

【C#16进制字符串转为byte数组,byte数组转换为16进制字符串】 /// 16进制字符转换为字节
private byte[] HexStringToByte(string hs)
{
string strTemp = "";
byte[] b = new byte[hs.Length / 2];
for (int i = 0; i < hs.Length / 2; i++)
{
strTemp = hs.Substring(i * 2, 2);
b[i] = Convert.ToByte(strTemp, 16);
}
//按照指定编码将字节数组变为字符串
return b;
}
private string ByteToHexString(byte[]data)
{
string strTemp = "";
for (int i = 0; i < data.Length; i++)
{
string a = Convert.ToString(data[i], 16).PadLeft(2, '0');
strTemp = strTemp + a;
}
return strTemp;
}

    推荐阅读