7

I am trying to interface with some system and in their specs they require to calculate CRC 16 for serial communication. Here is an extract from documentation

"16 bit CCITT CRC of the message utilizing the standard polynomial, X16 +X12 +X5 +1. Seed values are always 0 (zero)"

First of all I only found 2-3 samples of C# code of how to do it and none of the seem to give me the correct value. I tried this one http://www.sanity-free.com/133/crc_16_ccitt_in_csharp.html, but I am not sure what to set for initial value. I tried zeros and still doesn't work.

Data I am testing it with is:

0x00 0x09 0x10 0x01 0x01 0x7C 0xF4 0xB8 0x00, 

the CRC value I get is

0xF2 0x24, 

however their system says it should be

0xC0 0x2F

My understanding is that polynomial x16 + x12 + x5 + 1 = 0x11021, however even when I use this one in the code it still gives me wrong answer. What am I doing wrong?

dsolimano
  • 8,870
  • 3
  • 48
  • 63
fenix2222
  • 4,602
  • 4
  • 33
  • 56

1 Answers1

10

I figured it out. I had to use CRC16-CCITT Kermit inmplementation. I think their documentation needs to be updated as it uses a different polynomial.

http://www.sanity-free.com/147/standard_crc16_and_crc16_kermit_implementation_in_csharp.html

fenix2222
  • 4,602
  • 4
  • 33
  • 56
  • 4
    No, it's the same polynomial. It is very common for CRC implementations to use the bit-reversed polynomial. 0x1021 reversed is 0x8408. The description of the CRC16-CCITT Kermit CRC is at http://reveng.sourceforge.net/crc-catalogue/16.htm#crc.cat.kermit , which notes the reflection. – Mark Adler Mar 07 '13 at 15:53