CRC-CCITT 16-bit Python Manual Calculation

前端 未结 7 1281
情深已故
情深已故 2021-02-06 10:48

Problem

I am writing code for an embedded device. A lot of solutions out there for CRC-CCITT 16-bit calculations require libraries.

Given that u

7条回答
  •  面向向阳花
    2021-02-06 11:27

    Here's a function that I use:

    def crc16_ccitt(crc, data):
        msb = crc >> 8
        lsb = crc & 255
        for c in data:
            x = ord(c) ^ msb
            x ^= (x >> 4)
            msb = (lsb ^ (x >> 3) ^ (x << 4)) & 255
            lsb = (x ^ (x << 5)) & 255
        return (msb << 8) + lsb
    

提交回复
热议问题