Technical information
10/29/2014
Page 70 of 72
© 2014 The Code Corporation
12393 South Gateway Park Place Suite 600, Draper, UT 84020
(801) 495-2200
FAX (801) 495-0280
13 Appendix: Example CRC14 C Code
The CRC14 required by Host to Reader packets (see Section 6.2) can be calculated using the following
sample C code. This CRC14 consists of two consecutive bytes, each in range [0,127] most significant byte
first. A CRC16 is calculated on each packet byte, over the entire packet, excluding the prefix and the CRC16
itself. Bitwise AND each byte of the CRC16 checksum with 0x7F to generate the two bytes of the CRC14
checksum.
crc_t crc = 0;
<send firstByte>
crc = crc(crc, firstByte, firstByteSize);
<send secondByte>
crc = crc(crc, secondByte, secondByteSize)
<…>
crcHighByte = (crc >> 8) & 0x7f;
crcLowByte = crc & 0x7f;
<send crcHighByte>
<send crcLowByte>
The CRC16 is calculated in 12 Appendix: Example CRC16 C Code above.