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

Negative value bit shift with bit mask to long #21

Closed
fedex03 opened this issue Apr 9, 2018 · 2 comments
Closed

Negative value bit shift with bit mask to long #21

fedex03 opened this issue Apr 9, 2018 · 2 comments

Comments

@fedex03
Copy link

fedex03 commented Apr 9, 2018

Hi there,
looking into work library I found a bug into the temperature computation, in particular when the temperature in negative.

if (v & 0x80000000) { // Negative value, drop the lower 18 bits and explicitly extend sign bits. v = 0xFFFFC000 | ((v >> 18) & 0x00003FFFF); }

The bug regards ((v >> 18) & 0x00003FFFF

Here you perform a bit shift of 18 position to maintain the 14 temperature bit, but if you use this mask
0x00003FFFF you maintain 18 bit.

The right operations is to get a negative temperature are:

if (v & 0x80000000) { // Negative value, drop the lower 18 bits and explicitly extend sign bits. v = 0xFFFFC000 | ((v >> 18) & 0x00003FFF); }

Thanks for you work Adafruit!

Best regards,
Federico

@Ve2mrx
Copy link

Ve2mrx commented Sep 2, 2018

Hi!
Is your issue a duplicate of ##13 ?

Martin

@caternuson
Copy link
Contributor

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

3 participants