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