Skip to content

GPS时间解析的代码问题 #15

@tsingakbar

Description

@tsingakbar

(recvbuf[index] & 0xff - 0x30) + (recvbuf[index + 1] & 0xff - 0x30) * 10;

按照文档年月日时分秒都是ascii字符,解析时直接减去0x30(ascii的‘0’)即可得到对应的数值。
目前的实现digit & 0xff - 0x30,我理解本意应该是(digit & 0xff) - 0x30,其实也就等价于digit - 0x30
但是digit & 0xff - 0x30按照运算符优先级其实等价于digit & (0xff - 0x30),应该不是编码人的本意的,即其实等价于digit & 0b11001111;而digiet对应'0'-'9'的取值范围是0b00110000 - 0b00111001,运算后正好能确保左边4个bit取值为0,留下来右边4个bit,获得正确的数值。

咱就是说驱动能不能多少看一下编译器的warning啊……

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions