c# 串口的使用 :ASSCII转换位16
方法1 : data是传入的ascii码数据,最后返还一个16进制的数据
/// <summary> /// ASSCII转换位16 /// </summary> /// <param name="data">ascii码</param> public object AsEncon(string data) { byte[] ba = System.Text.ASCIIEncoding.Default.GetBytes(data); StringBuilder sb = new StringBuilder(); foreach (byte b in ba) { sb.Append(b.ToString("x")+" "); } //conPrint("AsEncon 转换16hex:" + sb); return sb; }