16進制字符串轉BCD碼


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}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM