Example #1
0
        /// <summary>
        /// 将数字形式的字符串转换为BCD
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static byte[] GetBytes(string str)
        {
            if (str == null || str == string.Empty)
            {
                throw new ArgumentException("string is null");
            }
            if (str.Length % 2 == 1)
            {
                str = "0" + str;
            }
            byte[] buf = new byte[str.Length / 2];

            for (int i = 0; i < buf.Length; i++)
            {
                int num = int.Parse(str.Substring(i * 2, 2));

                buf[i] = BCDCoder.GetBytes(num, 1)[0];
            }
            return(buf);
        }