这是转换的方法
public static byte[] HexStringToBinary(string hexstring)
{
string[] tmpary = hexstring.Trim().Split(' ');
byte[] buff = new byte[tmpary.Length];
for (int i = 0; i < buff.Length; i++)
{
buff[i] = Convert.ToByte(tmpary[i],16);//转换
}
return buff;
}
1.十六进制字符串转换为字节数组
private const string CharSet="0123456789ABCDEF";
int nLen=%%1.Length/2;
byte[] %%2=new byte[nLen];
for(int i=0;i
if(chs.Length<2) return -1;
%%2[i]=(byte)(CharSet.IndexOf(chs.Substring(i*2,1)*16+CharSet.IndexIf(chs.Substring(i*2+1,1)));
}
2.字节数组转换为十六进制字符串
byte[] todetail=%%1;
string %%2 = BitConverter.ToString(todetail,0,todetail.Length).Replace("-"," ");
你发01
02肯定是乱码啊,这俩是什么字符?
你发65
66
过来就是ab了