1 需要将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;
}
2 实际代码
public string NDEFHexToString(string hex) //------------------将16进制的字符串还原成原本的样子
//---