Skip to content

Instantly share code, notes, and snippets.

@devendranaga
Created September 5, 2016 20:06
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save devendranaga/fce8e166f4335fa777650493cb9246db to your computer and use it in GitHub Desktop.
Save devendranaga/fce8e166f4335fa777650493cb9246db to your computer and use it in GitHub Desktop.
NMEA checksum calculator in C
#include <stdio.h>
#include <string.h>
int nmea0183_checksum(char *nmea_data)
{
int crc = 0;
int i;
// the first $ sign and the last two bytes of original CRC + the * sign
for (i = 1; i < strlen(nmea_data) - 3; i ++) {
crc ^= nmea_data[i];
}
return crc;
}
@pmcmorris
Copy link

You may want to hoist strlen(nmea_data) out of the loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment