CRC and Checksum Examples

CRC Example

As an example of the CRC-16 computation, assume a packet with the following 7 bytes of data:
{0x34, 0x56, 0x00, 0x07, 0x01, 0x02, 0x03}
For example, this could be a packet carrying sequence number 0x34, acknowledgment number 0x56, having bits L, D, and A all set, and having 3 payload bytes 0x01, 0x02, and 0x03.

The 16-bit checksum for this data is: 0xc70e. Note that the binary representation of the CRC-16 polynomial is 0x18005.

The resulting packet would be:

{0xc7, 0x0e, 0x34, 0x56, 0x00, 0x07, 0x01, 0x02, 0x03}

Finally, if we prepend the length of 11, the packet will be:

{0x00, 0x0b, 0xc7, 0x0e, 0x34, 0x56, 0x00, 0x07, 0x01, 0x02, 0x03}

On the receiving end, the CRC computation will cover all bytes starting with "0x34" (the 5th byte) and go all the way to the end. The result should be 0xc70e.

Checksum Example

For the same packet, the checksum is 0x385f. The checksum is inverted and placed in the packet. The total packet will then be:
{0x00, 0x0b, 0xc7, 0xa0, 0x34, 0x56, 0x00, 0x07, 0x01, 0x02, 0x03}
(The high-order byte of the check value being the same for both checksum and CRC is a coincidence, and in general will not be the case).

Checksumming bytes 2-11 of the packet yields 0xffff, as is appropriate for an error-free packet.