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

int_to_bin assumes signed integer when converting to bytes #59

Closed
Nambarc opened this issue Mar 22, 2022 · 1 comment · Fixed by #61
Closed

int_to_bin assumes signed integer when converting to bytes #59

Nambarc opened this issue Mar 22, 2022 · 1 comment · Fixed by #61

Comments

@Nambarc
Copy link

Nambarc commented Mar 22, 2022

Problem was found when encoding a dictionary back into a NMEA message.

In the int_to_bin function in the util.py file, the second to last statement converts the value into bytes and then into a bit array. However, when the value is converted to_bytes it always assumes the value is signed.

I ran into an issue when encoding a message type 5 that had a draught value of 12.8. 12.8 gets multiplied up to 128 in the from_course function. 128 is then ultimately passed to int_to_bin and expected to fit into 1 byte. However, a signed value of 128 doesn't fit into 1 byte. So I think int_to_bin needs to be told the signed-ness of the value from the calling function, it can't always be set to signed=True.

@M0r13n
Copy link
Owner

M0r13n commented Mar 26, 2022

Hey @Nambarc,

thanks for bringing this up. You are right. This will be fixed with #61 and will be available in the next release.

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

Successfully merging a pull request may close this issue.

2 participants