Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tsingakbar opened this issue Dec 12, 2023 · 0 comments
Open

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

tsingakbar opened this issue Dec 12, 2023 · 0 comments

Comments

@tsingakbar
Copy link

(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啊……

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant