title: CRC16-CCITT (x.25) Checksum Calculation Problems
body: <p>I have read about a helpful website with a CRC calculator covered in other posts, which works great, but the code provided in C language does not replicate the capabilities, unfortunately:
  <a href="http://www.zorc.breitbandkatze.de/crc.html" rel="nofollow">http://www.zorc.breitbandkatze.de/crc.html</a></p>
  
  <p>The following configuration is required for CRC16-CCITT (x.25), which is the format I am working with for a sensor and supporting electronic assembly:</p>
  
  <ul>
  <li>CRC Order: 16</li>
  <li>CRC polynomial: 0x11021 [entered as 1021]</li>
  <li>Initial value: 0xffff [entered as ffff]</li>
  <li>Direct/Indirect: Direct</li>
  <li>Final XOR Value: 0xffff [entered as ffff]</li>
  <li>Reverse Data Bytes: True</li>
  <li>Reverse CRC Result Before Final XOR: True</li>
  </ul>
  
  <p>However, <strong>sometimes an incorrect CRC is calculated using the C code</strong>,       specifically, but comes out correct with the online calculator. </p>
  
  <p>You can find the C code at the following link, but make sure to change the configuration options to match the above:
  <a href="http://www.zorc.breitbandkatze.de/crctester.c" rel="nofollow">http://www.zorc.breitbandkatze.de/crctester.c</a></p>
  
  <p>Here is a sample packet placed in the C Code:</p>
  
  <pre><code>const char string[] = { "\x82\x2f\x0a\x40\x00\x00\x7a\x44" };
  </code></pre>
  
  <p>This returns an incorrect CRC of "0x1e4e".</p>
  
  <p>and in the online calculator:
  "%82%2f%0a%40%00%00%7a%44"</p>
  
  <p>Which returns the correct CRC of "0xd831".</p>
  
  <p>Also, you will want a packet that works with BOTH the online calculator AND the C Code, which follows.</p>
  
  <p>In the C Code:</p>
  
  <pre><code>const char string[] = { "\x81\x2f\x0b\x4f\xd8\xab\x0d\x42\xed" };
  </code></pre>
  
  <p>And in the online calculator:
  "%81%2f%0b%4f%d8%ab%0d%42%ed"</p>
  
  <p>Does anyone know why this is happening, and how the C Code can be corrected to fix this?</p>
  
  <p>Thank you so much for considering to help!</p>