每一行末尾的“星号”后面都有两位校验,是本行字符串中将“美元符号”和“星号”之间的每一个字符从左至右依次进行异或等于运算而得到的
$GPGSV,2,2,07,24,71,118,51,27,02,300,37,32,08,258,4141
$GLGSV,2,1,07,66,46,058,48,82,29,260,44,76,43,059,47,77,38,150,4366
$GLGSV,2,2,07,81,09,213,40,67,48,329,48,68,06,291,3957
$GAGSV,2,1,06,04,69,007,48,09,33,287,43,11,35,240,41,12,10,190,3765
$GAGSV,2,2,06,19,25,078,32,01,38,114,4366
$BDGSV,3,1,10,01,37,146,43,02,34,226,38,03,43,190,42,06,72,343,476C
$BDGSV,3,2,10,08,26,191,41,09,57,287,44,13,39,210,42,16,70,329,4966
$BDGSV,3,3,10,04,26,124,38,05,16,249,366D
计算一条BDGSV的校验和为例
#include <stdio.h>int main()
{char str[] = "$BDGSV,3,3,10,04,26,124,38,05,16,249,36*6D";int i = 0;int result = str[1];for(i = 2; str[i] != '*'; i++){result ^= str[i];}printf("result=%x\n", result);return 0;
}
计算结果