1 将字符串转成int型 普通的 仅限数字型的
int temp = int.Parse(hex.Substring(index, 2)); //------------将字符串转为整数 01为01
2 将字符串转成int型的 字符串是16进制的数字 如0a
int temp = int.Parse(hex.Substring(index, 2),System.Globalization.NumberStyles.HexNumber);
如 0a 为 10
3 将 16 进制形式的字符串转成 10进制数组
private static byte[] strToHexByte(string hexString) //----------------将16进制的字符串转成10进制的字节数组
{
byte[] returnBytes = null;
if(!string.IsNullOrEmpty(hexString)) //----------代表有效
{
hexString.Replace(" ", ""); //---------去掉空格
if(hexString.Length % 2 != 0)
{
hexString += " "; //---------变成偶数
}
returnBytes = new byte[hexString.Length / 2];
int index = 0;
for(int i = 0; i < returnBytes.Length; i ++)
{
returnBytes[i] = Convert.ToByte(hexString.Substring(index, 2), 16); //-----------每一次取两位数 按照16进制转成10进制字节数组
index += 2;
}
}
return returnBytes;
}
4 string.Empty 是对直接赋值 “ “ 的优化写法