Serial Port

2018-04-13
16进制转化字节数组


private byte[] HexStringToByteArray(string s)
{
    s = s.Replace(“ ”,"");
    byte[] buffer = new byte[s.Length/2];
    for(int i=0;i

字节数组转化为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;
}

你可能感兴趣的:(Serial Port)