b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

循环冗余校验_循环冗余校验码计算_循环冗余校验 java实现(4)

电脑杂谈  发布时间:2017-03-31 08:08:44  来源:网络整理

unsigned short do_crc(unsigned char *message, unsigned int len)

{

unsigned short crc_reg = 0;

while (len--)

crc_reg = (crc_reg >> 8) ^ crc16_ccitt_table[(crc_reg ^ *message) & 0xff];

return crc_reg;

}

crc16_ccitt_table通过以下代码生成:

int main()

{

unsigned char index = 0;

unsigned short to_xor;

int i;

printf("unsigned short crc16_ccitt_table[256] =\n{");

while (1)

{

if (!(index % 8))

printf("\n");

to_xor = index;

for (i = 0; i < 8; i)

{

if (to_xor & 0x0001)

to_xor = (to_xor >> 1) ^ 0x8408;

else

to_xor >>= 1;

}

printf("0x%04x", to_xor);

if (index == 255)

{

循环冗余校验码计算_循环冗余校验_循环冗余校验 java实现

printf("\n");

break;

}

else

{

printf(", ");

index;

}

}

printf("};");

return 0;

}

生成的表如下:

unsigned short crc16_ccitt_table[256] =

{

0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,

0x88, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,

0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,

0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,

0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,

0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,

0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,

0xbdcb, 0xa2, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,

0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,

0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,

0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-38614-4.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...