C#进制转换

字符串转十进制

string data = "01 06 00 AA 00 03 E9 EB";
data = data.Replace(" ", "");
byte[] orderBytes = new byte[data.Length / 2];
for (int i = 0; i < orderBytes.Length; i++)
{
    orderBytes[i] = Convert.ToByte(data.Substring(i * 2, 2), 16);
}

  

十进制转十六进制

string strHex = "";
for(int i=0;i<orderBytes.Length;i++)
{
    strHex+=string.Format("{0:x}",orderBytes[i]).ToString().PadLeft(2, '0');
}
原文地址:https://www.cnblogs.com/showonce/p/15691846.html