ZHCUC57E August 2016 – July 2024
以下伪代码演示了一种实现 CRC 计算的可能方法。
“^”代表按位异或运算符。
“in”是包含在 CRC 中的数据字节。
“crc”是正在计算的 CRC 字节。
CRC(0)(7:0)=0xFF; # Initial seed value is 0xFF.
FOR x=1 to N; # Loop through all "N" data bytes that are included in the CRC.
CRC(x)(0)=IN(x)(0)^IN(x)(6)^IN(x)(7)^CRC(x-1)(0)^CRC(x-1)(6)^CRC(x-1)(7);
CRC(x)(1)=IN(x)(0)^IN(x)(1)^IN(x)(6)^CRC(x-1)(0)^CRC(x-1)(1)^CRC(x-1)(6);
CRC(x)(2)=IN(x)(0)^IN(x)(1)^IN(x)(2)^IN(x)(6)^CRC(x-1)(0)^CRC(x-1)(1)^CRC(x-1)(2)^CRC(x-1)(6);
CRC(x)(3)=IN(x)(1)^IN(x)(2)^IN(x)(3)^IN(x)(7)^CRC(x-1)(1)^CRC(x-1)(2)^CRC(x-1)(3)^CRC(x-1)(7);
CRC(x)(4)=IN(x)(2)^IN(x)(3)^IN(x)(4)^CRC(x-1)(2)^CRC(x-1)(3)^CRC(x-1)(4);
CRC(x)(5)=IN(x)(3)^IN(x)(4)^IN(x)(5)^CRC(x-1)(3)^CRC(x-1)(4)^CRC(x-1)(5);
CRC(x)(6)=IN(x)(4)^IN(x)(5)^IN(x)(6)^CRC(x-1)(4)^CRC(x-1)(5)^CRC(x-1)(6);
CRC(x)(7)=IN(x)(5)^IN(x)(6)^IN(x)(7)^CRC(x-1)(5)^CRC(x-1)(6)^CRC(x-1)(7);
END FOR;