怎样计算异或校验和

来源:百度知道 编辑:UC知道 时间:2024/05/21 11:51:59
判断$与*之间的异或是不是4C
$GPGGA,085014.955,2839.2050,N,11549.5721,E,1,04,03.6,76.6,M,-6.2,M,,*4C
怎么计算啊

#include <stdio.h>

void main ()
{
char a[]="$GPGGA,085014.955,2839.2050,N,11549.5721,E,1,04,03.6,76.6,M,-6.2,M,,*4C";
int i,result;

for(result=a[1],i=2;a[i]!='*';i++)
{
result^=a[i];
}
printf("result = %x\n",result);
}

运行结果为:4c

#include <stdio.h>

void main () {
int result = '$' ^ '*';
printf("result = %x\n",result);

}
运行结果为e

那位高金山的qq是多少啊!能否加你 啊