CRC的原理和实现问题研究..
点击数:7199 次 录入时间:03-04 11:46:23 整理:http://www.55dianzi.com PLC入门
0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(248,252,253); orphans: auto; widows: auto; webkit-text-stroke-width: 0px">
} return crc_reg;} 该算法使用了两层循环,对消息逐位进行处理,这样效率是很低的。为了提高时间效率,通常的思想是以空间换时间。考虑到内循环只与当前的消息字节和crc_reg的低字节有关,对该算法做以下等效转换: unsigned short do_crc(unsigned char *message, unsigned int len){ int i, j; unsigned short crc_reg = 0; unsigned char index; unsigned short to_xor; for (i = 0; i < len; i++) { index = (crc_reg ^ message[i]) & 0xff; to_xor = index; for (j = 0; j < 8; j++) { if (to_xor & 0x0001) to_xor = (to_xor >> 1) ^ 0x8408; else to_xor >>= 1; [1] [2] 下一页
本文关键字:暂无联系方式PLC入门,plc技术 - PLC入门