下面以多项式:x8+x4+x3+x2+1(0x1D)
算法初始值:0xFF
为例,在Python中实现,Motorola格式
代码如下:
ptr=[0x78];
lenth=len(ptr);
print(lenth);
def crc_high_first( ptr,lenth):
crc=0xff;
for iptr in ptr:
crc ^= iptr;
for index in range(8):
if (crc & 0x80):
crc = (crc << 1) ^ 0x1d;
else:
crc = (crc << 1);
print("crc===%02x" % crc);
str_crc='0x{:02x}'.format(crc & 0xff)
print(str_crc);
crc_high_first(ptr,lenth);
结算结果:
结果对比: