示例#1
0
        /// <summary>
        /// 生成FCS校验值
        /// </summary>
        /// <param name="ccc"></param>
        /// <returns></returns>
        public static byte[] makeCrc16(byte[] ccc)
        {
            CRC16Util crc16 = new CRC16Util();

            crc16.reset();
            crc16.update(ccc);
            //Console.WriteLine(RealHexToStr(crc16.getCrcValue().ToString()));
            byte[] test = intToByte(crc16.getCrcValue());
            //log(RealHexToStr(crc16.getCrcValue().ToString()));
            return(test);
        }
示例#2
0
        public static String getCrc16Code(String crcString)
        {
            // 转换成字节数组
            byte[] creBytes = HexString2Bytes(crcString);

            // 开始crc16校验码计算
            CRC16Util crc16 = new CRC16Util();

            crc16.reset();
            crc16.update(creBytes);
            int crc = crc16.getCrcValue();
            // 16进制的CRC码
            String crcCode = Convert.ToString(crc, 16).ToUpper();

            // 补足到4位
            if (crcCode.Length < 4)
            {
                // crcCode = StringUtil.lefgPadding(crcCode, '0', 4);
                crcCode = crcCode.PadLeft(4, '0');
            }
            return(crcCode);
        }