下面是CRC的表格
CRCH = { 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64 } CRCL = { 0, 192, 193, 1, 195, 3, 2, 194, 198, 6, 7, 199, 5, 197, 196, 4, 204, 12, 13, 205, 15, 207, 206, 14, 10, 202, 203, 11, 201, 9, 8, 200, 216, 24, 25, 217, 27, 219, 218, 26, 30, 222, 223, 31, 221, 29, 28, 220, 20, 212, 213, 21, 215, 23, 22, 214, 210, 18, 19, 211, 17, 209, 208, 16, 240, 48, 49, 241, 51, 243, 242, 50, 54, 246, 247, 55, 245, 53, 52, 244, 60, 252, 253, 61, 255, 63, 62, 254, 250, 58, 59, 251, 57, 249, 248, 56, 40, 232, 233, 41, 235, 43, 42, 234, 238, 46, 47, 239, 45, 237, 236, 44, 228, 36, 37, 229, 39, 231, 230, 38, 34, 226, 227, 35, 225, 33, 32, 224, 160, 96, 97, 161, 99, 163, 162, 98, 102, 166, 167, 103, 165, 101, 100, 164, 108, 172, 173, 109, 175, 111, 110, 174, 170, 106, 107, 171, 105, 169, 168, 104, 120, 184, 185, 121, 187, 123, 122, 186, 190, 126, 127, 191, 125, 189, 188, 124, 180, 116, 117, 181, 119, 183, 182, 118, 114, 178, 179, 115, 177, 113, 112, 176, 80, 144, 145, 81, 147, 83, 82, 146, 150, 86, 87, 151, 85, 149, 148, 84, 156, 92, 93, 157, 95, 159, 158, 94, 90, 154, 155, 91, 153, 89, 88, 152, 136, 72, 73, 137, 75, 139, 138, 74, 78, 142, 143, 79, 141, 77, 76, 140, 68, 132, 133, 69, 135, 71, 70, 134, 130, 66, 67, 131, 65, 129, 128, 64 }
下面是CRC查表算法
变量名 | 类 型 | 静态 | 数组 | 备 注 | CRCHi | 整数型 | | | CRCLo | 整数型 | | | i | 整数型 | | | 索引 | 整数型 | | | 临时CRC | 文本型 | | | CRC | 整数型 | | |
CRCHi = 255 CRCLo = 255 计次循环首 (取数组成员数 (校验内容 ), i )索引 = 位异或 (CRCHi, 校验内容 )CRCHi = 位异或 (CRCLo, CRCH [索引 + 1 ])CRCLo = CRCL [索引 + 1 ]计次循环尾 ()CRC = 位或 (左移 (CRCHi, 8 ), CRCLo )临时CRC = 十到十六 (到长整数 (CRC )) 如果真 (取文本长度 (临时CRC ) = 1 )临时CRC = “000” + 临时CRC 如果真 (取文本长度 (临时CRC ) = 2 )临时CRC = “00” + 临时CRC 如果真 (取文本长度 (临时CRC ) = 3 )临时CRC = “0” + 临时CRC 返回 (临时CRC) |
CRC16_MODBUS | 整数型 | | |
欲校验的整数 | 字节集 | | | |
变量名 | 类 型 | 静态 | 数组 | 备 注 | crc | 整数型 | | | table | 整数型 | | 256 | i | 整数型 | | | 变量循环首 (0, 255, 1, i )crc = i 变量循环首 (1, 8, 1, )如果 (位与 (crc, 1 ) ≠ 0 )crc = 位异或 (右移 (crc, 1 ), 40961 ) crc = 右移 (crc, 1 )变量循环尾 ()table [i + 1 ] = crc 变量循环尾 ()crc = 65535 变量循环首 (1, 取字节集长度 (欲校验的整数 ), 1, i )crc = 位异或 (右移 (crc, 8 ), table [位异或 (欲校验的整数 [i ], 位与 (crc, 255 )) + 1 ])变量循环尾 ()返回 (crc )
|