Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要python校验和的帮助吗_Python_Python 2.7 - Fatal编程技术网

需要python校验和的帮助吗

需要python校验和的帮助吗,python,python-2.7,Python,Python 2.7,我从中国购买了一台汽车追踪器,但遇到了一个问题。制造商只向我发送了下面的函数 有谁能帮助我如何使用python进行此校验和: Checksum (2 byte)* Unsigned char Checksum (const char *s,int Length) { Unsigned char result; result = 0; for(int i=0;i<Length;i++) { result ^=*s++ }

我从中国购买了一台汽车追踪器,但遇到了一个问题。制造商只向我发送了下面的函数

有谁能帮助我如何使用python进行此校验和:

Checksum (2 byte)*

Unsigned char Checksum (const char *s,int Length)
{
    Unsigned char result;

    result = 0;

    for(int i=0;i<Length;i++)
    {
        result ^=*s++
    }

    return result;
}
给你:

s = "test"
chk = reduce(lambda a,b : a^b, [ord(c) for c in s])

print "Checksum : ", chk, " \n"

您问题中的代码在C/C++中无效(假设它是正确的)。请尝试使用python添加代码片段-显示了所做的努力。这段代码是我在internet上购买的GPS跟踪器附带的。这是为了发送GPRS命令。。
s = "test"
chk = reduce(lambda a,b : a^b, [ord(c) for c in s])

print "Checksum : ", chk, " \n"
sh-4.3$ python main.py                                                                                         
Checksum :  22