用于校验GPS报文指令的有效性 很简单的代码,留存吧
public static bool Verify(string gpsInfo) {
if (gpsInfo == null || "".Equals(gpsInfo))
return false;
char p = gpsInfo[0];
char c = (char)0;
int i = 1;
for (; i < gpsInfo.Length; i++)
{
p = gpsInfo[i];
if (p == '*')
break;
c ^= p;
}
if (p != '*')
return false;
return gpsInfo.Substring(++i).Equals(string.Format("{0:X}", (int) c));
}
--------------------------------------