Link to home
Create AccountLog in
Avatar of akiles99
akiles99Flag for India

asked on

Checksum(Vb+php)

Hi,
I need a PHP Function returns a NMEA Checksum based on the string given.

its simple XOR formula.

 http://www.codepedia.com/1/Calculating+and+Validating+NMEA+Checksums ...

Thanks ,
akiles
#define NIBBLE2HEX(c) ((c) > 9 ? (c) + 'A' - 10 : (c) + '0') 
 
// buf is a char[] array which contains the NMEA sentence without trailing checksum. 
// E.g. "$FRLIN,,user1,8IVHF" and "*7A" will be added 
// buf_inx is an index to the last free position in the buffer 
 
int checksum = 0; 
int inx; 
for(inx = 1; inx < buf_inx; inx++) 
{ 
	checksum ^= buf[inx]; 
} 
buf[buf_inx++] = '*'; 
buf[buf_inx++] = NIBBLE2HEX((checksum >> 4) & 0xf); 
buf[buf_inx++] = NIBBLE2HEX(checksum & 0xf);

Open in new window

Avatar of akiles99
akiles99
Flag of India image

ASKER

urgent please....
ASKER CERTIFIED SOLUTION
Avatar of jopie916
jopie916

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
good....