• C# CRC


      public static string CRC16(string cmdString)
            {
                try
                {
                    //CRC寄存器
                    //int CRCCode = 0;
                  
                    ushort crc = 0xFFFF;
                    for (int i = 0; i < cmdString.Length / 2; i++)
                    {
                        ushort cmdHex =(ushort)Convert.ToInt16( cmdString.Substring(i * 2, 2),16);
                        crc = (ushort)(crc ^ (cmdHex));
                        for (int j = 0; j < 8; j++)
                        {
                            crc = (crc & 1) != 0 ? (ushort)((crc >> 1) ^ 0xA001) : (ushort)(crc >> 1);
                        }
                    }
                    byte hi = (byte)((crc & 0xFF00) >> 8); //高位置
                    byte lo = (byte)(crc & 0x00FF); //低位置
                    string his = Convert.ToString(hi, 16);
                    string los = Convert.ToString(lo, 16);
                    string res = los + his;
                    return res;
                 
                      
                  
                }
                catch
                {
                    throw;
                }
            }
  • 相关阅读:
    Struts类型转换
    Oracle的学习,知识点整理
    常用的Oracle_SQL语句
    Oracle的优化
    Oracle创建表空间,用户,授权
    Linux权限的控制
    Oracle实例的3种连接方式和所使用的连接工具
    Oracle数据库打开端口
    Hibernate一对多配置
    hibernate UUID问题
  • 原文地址:https://www.cnblogs.com/xuchanghua/p/12125694.html
Copyright © 2020-2023  润新知