来自链接 https://blog.youkuaiyun.com/spw55381155/article/details/80755901
这个主要用于格式化通信数据数组.
private void button6_Click(object sender, EventArgs e)
{
byte[] l_bytes = new byte[4];
l_bytes[0] = 154;
l_bytes[1] = 153;
l_bytes[2] = 33;
l_bytes[3] = 65;
StringBuilder ret = new StringBuilder();
foreach (byte b in l_bytes)
{
//{0:X2} 大写, {0:x2} 小写
//这里以空格分割
ret.AppendFormat("{0:X2}{1}", b, " ");
}
Console.WriteLine("{0}", ret.ToString());
}