15位IMEI字符串转8位BCD码
public static string SwapStr(string str)
{
return (str.Substring(1, 1) + str.Substring(0, 1));
}
public static byte[] HexStrToBCD(string hexString)
{
hexString = hexString.Replace(" ", "").Trim();
if (hexString.Length % 2 != 0){
hexString += "F";
}
byte[] returnBytes = new byte[hexString.Length / 2];
for (int i = 0; i < returnBytes.Length; i++) {
returnBytes[i] = Convert.ToByte(SwapStr(hexString.Substring(i * 2, 2).Trim()), 16);
}
return returnBytes;
}
"869300038715250"-->{0x68,0x39,0x00,0x30,0x78,0x51,0x52,0xF0}