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

Left Shift Overflows #41

Open
begeistert opened this issue Jul 7, 2023 · 0 comments
Open

Left Shift Overflows #41

begeistert opened this issue Jul 7, 2023 · 0 comments

Comments

@begeistert
Copy link

begeistert commented Jul 7, 2023

This issue is related to a bad conversion, when you try to do a left shit of 16-bit, this will lead to an overflow, and the result will be zero, this means that the number is considered an integer, CLanguage should be able to convert this shift to a long value and don't return a zero, this happens in Arduino

byte  pressure_data_high = readRegister(0x1F, 1);
 pressure_data_high &= 0b00000111; //you only needs bits 2 to 0

 //Read the pressure data lower 16 bits:
 unsigned int pressure_data_low = readRegister(0x20, 2);
 //combine the two parts into one 19-bit number:
 long pressure = ((pressure_data_high << 16) | pressure_data_low) / 4;
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