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

时间:2014-08-12 18:27:34   收藏:0   阅读:273

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



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

c#代码实现GPS数据的有效性校验,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!