Skip to content

correct calculation in greaseunpack for 2 byte value#54

Open
erpebe wants to merge 1 commit intoadafruit:mainfrom
erpebe:main
Open

correct calculation in greaseunpack for 2 byte value#54
erpebe wants to merge 1 commit intoadafruit:mainfrom
erpebe:main

Conversation

@erpebe
Copy link
Copy Markdown

@erpebe erpebe commented Mar 24, 2025

File greasepack.h
The calculation in greaseunpack for a 2 byte code (values between 250..1524) was wrong

Example
encoding the value 1000 in greaspack()
unsigned high = (value - 250) / 255; -> (1000 - 250) / 255 => 2
*buf++ = 250 + high; -> 250 + 2 => 252
*buf++ = 1 + (value - 250) % 255; -> 1 + (1000 - 250) % 255 => 241

decoding 252, 241
old: (252 - 250 + 1) * 250 + 241 => 991 wrong
new: 250 + (252 -250) * 255 + 241 -1 => 1000 correct

The calculation in greaseunpack for a 2 byte code (values between 250..1524) was wrong
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 this pull request may close these issues.

1 participant