uint8_t crc5_itu(uint8_t *data, uint16_t length) { uint8_t i; uint8_t crc = 0; // Initial value while(length--) { crc ^= *data++; // crc ^= *data; data++; for (i = 0; i < 8; ++i) { if (crc & 1) crc = (crc >> 1) ^ 0x15;// 0x15 = (reverse 0x15)>>(8-5) else crc = (crc >> 1); } } return crc; }转为python
时间: 2024-02-14 20:24:10 浏览: 66
code uint8-t *p-flash 与uint8-t code *p-flash的区别
def crc5_itu(data, length):
crc = 0
i = 0
while length > 0:
length -= 1
crc ^= data[i]
i += 1
for j in range(8):
if crc & 1:
crc = (crc >> 1) ^ 0x15
else:
crc = (crc >> 1)
return crc
阅读全文