c#代码实现GPS数据的有效性校验

用于校验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));
        }



--------------------------------------

原文地址:https://www.cnblogs.com/gc2013/p/3907554.html