Please help me some math or C gurus,
I am in no way a math or C expert and this has made realy
huble.
My system calculates checksums based on the National Marine
Electronics Association standard. The standard is supported by most
GPS systems. I need to generate a hexadecimal number using the
checksum of a string according to this and attached C code as an
example.
The format of an NMEA sentence is as follows:
$GPRMC,235947.000,V,0000.0000,N,00000.0000,E,,,041299,,*1D<Carriage
return>
The checksum immediately follows the ‘*’
(asterisk) character and is computed by taking the bit-wise
exclusive-OR of all characters between the ‘$’ (dollar
sign) and the ‘*’ (asterisk). The checksum is
represented in hexadecimal and is 1D (decimal 29) for the example
sentence above.
The following standard C code demonstrates the checksum
calculation.
#include <stdio.h>
unsigned char calc_checksum(const char *s)
{
unsigned char result;
result = 0;
s++; // Skip dollar sign
while ((*s != '*') && (*s != '\0'))
result ^= *s++;
return result;
}
int main()
{
unsigned char checksum;
checksum = calc_checksum
("$GPRMC,235947.000,V,0000.0000,N,00000.0000,E,,,041299,,*");
printf("Checksum = %02X\n", checksum);
return 0;
}
When executed, the program should produce the following
output:
Checksum = 1D
Could some one help me translating this into CF, CF script or
Javascript?
The rest I can do my self.
Bosse Persson