/// <summary>
        /// 把号码用BCD进行压缩编码。
        /// </summary>
        /// <param name="Num8BitByte">The num8 bit byte.</param>
        /// <returns></returns>
        public static byte[] ByteArrayToBCD(byte[] Num8BitByte)//8位的ascii码
        {
            byte[] Num4bitByte = new byte[8];

Num4bitByte = BitConverter.GetBytes(0xffffffffffffffff);
            for (int i = 0; i<Num8BitByte.Length; i++)
            {
                byte num =Convert.ToByte(Num8BitByte[i] - 0x30);
                if (i % 2 == 0)
                {
                    Num4bitByte[i / 2] = Convert.ToByte((Num4bitByte[i / 2] & 0xF0) | num);
                }
                else
                {
                    Num4bitByte[i / 2] = Convert.ToByte((Num4bitByte[i / 2] &0x0F)| (num << 4));
                }
                  
            }
            
            return Num4bitByte;
        }

/// <summary>
        /// BCDs to string.
        /// </summary>
        /// <param name="bcdNum">The BCD num.</param>
        /// <returns></returns>
        public static string bcdToString(byte[] bcdNum)
        {
            string retString="";
            byte[] byteChar = new byte[bcdNum.Length];
            byteChar = BitConverter.GetBytes(0xffffffffffffffff);
            byte tempHigh=0,tempLow=0;
            int i = 0;
            while (tempHigh != 0x0F && tempLow != 0xF0)
            {
                tempHigh = Convert.ToByte(bcdNum[i] & 0xF0);//取出高四位;
                tempHigh = Convert.ToByte(tempHigh >> 4);
                tempLow = Convert.ToByte((bcdNum[i] & 0x0F) << 4);
                byteChar[i] = Convert.ToByte(tempLow | tempHigh);
                i++;
            } 
            string[] HexString=BitConverter.ToString(byteChar).Trim().Split('-');
            foreach (string str in HexString)
            {
                retString += str.Trim();
            }
            int LastIndex = retString.IndexOf('F');
            return retString = retString.Substring(0, LastIndex);
        }

最新文章

  1. Jetson ARM SeetaFace编译
  2. WordPress上传含有中文文件出现乱码
  3. ECS挂载数据盘
  4. hihoCoder #1174 : 拓扑排序&#183;一 (判断循环图)
  5. Unity3D TestTool Part _1
  6. Desert King
  7. linux 定时执行shell
  8. 龙杰ACR122S NFC读卡器
  9. 在VS上配置OpenCV
  10. Android-----js和android的互调
  11. JAVA加密算法系列-AesEBC
  12. Day6 Numerical simulation of optical wave propagation之通过随机介质(如大气湍流)的传播(二)
  13. [mock open]PyUnit执行单元测试时使用字符串模拟文件对象
  14. 如何禁止某个linux用户访问某些文件夹及执行某些命令
  15. 【spring基础】AOP概念与动态代理详解
  16. linux 如何快速的查找日志中你所要查找的信息
  17. .net 多线程的使用(Thread)
  18. 《Java多线程编程核心技术》学习笔记
  19. Apache Rewrite(大小写)
  20. Sa身份登陆SQL SERVER失败的解决方案

热门文章

  1. C 调用 lua 函数
  2. centos 7 下安装haproxy
  3. C++函数指针和类成员函数指针
  4. PHPstorm配置远程及本地服务器
  5. PHP编译configure时常见错误
  6. 解决android studio引用远程仓库下载慢(转)
  7. Hadoop科普文—常见的45个问题解答 &amp;#183; Hadoop
  8. 怎么用ChemDraw Pro绘制不定域共轭环
  9. ios -完全实现代码设置 Could not find a storyboard named &#39;Main&#39; in bundle NSBundle
  10. MySQL文件和Innodb引擎文件