title: NMEA checksum calculation calculation
body: <p>I am trying to find checksum for NMEA sentence which is already calculated by GPS.</p>
  
  <pre><code>char GPRMCBuf[POS_BUFFER] = {0xA0, 0xA2, 0x00, 0x48, 0xDD, 
       0x24, 0x47, 0x50, 0x52, 0x4D, 0x43, 0x2C, 0x31, 0x35, 
       0x30, 0x35, 0x32, 0x30, 0x2E, 0x30, 0x30, 0x30, 0x2C, 
       0x41, 0x2C, 0x34, 0x31, 0x32, 0x31, 0x2E, 0x37, 0x39, 
       0x37, 0x37, 0x2C, 0x4E, 0x2C, 0x30, 0x30, 0x32, 0x31, 
       0x30, 0x2E, 0x39, 0x36, 0x36, 0x37, 0x2C, 0x45, 0x2C, 
       0x31, 0x2E, 0x35, 0x30, 0x2C, 0x35, 0x38, 0x2E, 0x32, 
       0x39, 0x2C, 0x32, 0x33, 0x30, 0x37, 0x31, 0x35, 0x2C, 
       0x2C, 0x2C, 0x41, 0x2A, 0x35, 0x38, 0x0D, 0x0A, 0x0F, 
       0x05, 0xB0, 0xB3};
  </code></pre>
  
  <p>hear last 3rd and 4th char are checksum that is 0F05
  but we want to correct algorithm. Our algorithm which we used is as follows</p>
  
  <pre><code>Index = first,
  checkSum = 0,
  while index &lt; msgLen,
  checkSum = checkSum + message[index],
  checkSum = checkSum AND (2^15-1).
  increment index.
  </code></pre>
  
  <p>code we have written is as follows:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  main()
  {
      unsigned char i;
      unsigned short chk;
  
      char test[]={ 0x47, 0x50, 0x52, 0x4D, 0x43, 0x2C, 0x31, 
              0x35, 0x30, 0x35, 0x32, 0x30, 0x2E, 0x30, 0x30, 
              0x30, 0x2C, 0x41, 0x2C, 0x34, 0x31, 0x32, 0x31, 
              0x2E, 0x37, 0x39, 0x37, 0x37, 0x2C, 0x4E, 0x2C, 
              0x30, 0x30, 0x32, 0x31, 0x30, 0x2E, 0x39, 0x36, 
              0x36, 0x37, 0x2C, 0x45, 0x2C, 0x31, 0x2E, 0x35, 
              0x30, 0x2C, 0x35, 0x38, 0x2E, 0x32, 0x39, 0x2C, 
              0x32, 0x33, 0x30, 0x37, 0x31, 0x35, 0x2C, 0x2C, 
              0x2C, 0x41,0x2A, 0x35, 0x38, 0x0D, 0x0A}; 
  
      chk = 0;
  
      for(i = 0; i &lt; 70; i++)
      {    
          chk = chk + test[i];
          chk = chk &amp; 32767;  
      }
      printf("A=%hu\n", chk);
      return 0;
  }
  </code></pre>
  
  <p>problem is that we are getting 3588 but it should be 3845(0F05).</p>
  
  <p>Please help us to solve this algorithm.</p>