2018-04-13
16进制转化字节数组
private byte[] HexStringToByteArray(string s)
{
s = s.Replace(“ ”,"");
byte[] buffer = new byte[s.Length/2];
for(int i=0;i<s.Length;i+=2)
buffer[i/2] =(byte)Convert.ToByte(s.Substring(i,2),16);
return buffer;
}
字节数组转化为16进制字符串
private string ByteArrayToHexString(byte[] data)
{
StringBuilder sb = new StringBuilder(data.Length*3);
foreach(byte b indata)
sb.Append(Convert.ToString(b,16).PadLeft(2,'0'));
return sb.ToString().ToUpper;
}
网友评论