-
Notifications
You must be signed in to change notification settings - Fork 2.1k
sys/bcd: add bcd_buf_from_u32() #21308
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
Conversation
Isn't the dec_as_hex the same as binary coded decimals? I think there is already a helper for that. |
hah you are right! |
Sounds good to me. I'd personally search such a function in the bcd module, though. How about moving it there? |
I also thing that such a function in a string header is somewhat misleading. |
Ok, will move it to a new |
There already is https://doc.riot-os.org/group__sys__bcd.html |
Yes but that's just a header file 😉 |
I renamed the function and moved it to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't shake the feeling off that there's a off-by-one error in it. Oh well, can't find it nor proof it. So looks good to me! :D
Contribution description
This adds two helper functions to the
string_utils
library:reverse_buf()
that inverts the order of bytes in an arraybcd_buf_from_u32()
that takes a numbera
and calculates a numbera'
so that the hex string representation ofa'
is the same as the decimal string representation ofa
. e.g.bcd_buf_from_u32(123)
would produce0x123
.Testing procedure
This can be used to to generate pretty MAC / IP addresses from decimal serial numbers:
Issues/PRs references