How many binary bits you need to convert, signed or unsigned?I think we all know that “double dabble” is the best binary to bcd algorithm for processors with no multiply and limited memory, but what is the best algorithm for processors with a single-cycle multiply and no shortage of memory?
32 bits, on a cortex M4How many binary bits you need to convert, signed or unsigned?
Does the MCU have integer divide?
What MCU are you usiing?
If you write it in C to be easy to understand, and general for most use cases, without fancy coding tricks, the compiler optimization will make it close to best. Best is not always Best.32 bits, on a cortex M4
No shortage of memory?I think we all know that “double dabble” is the best binary to bcd algorithm for processors with no multiply and limited memory, but what is the best algorithm for processors with a single-cycle multiply and no shortage of memory?
This is how we did logarithms for real-time data processing back in the 90s.No shortage of memory?
A look-up table.
There are several way to represent BCD, e.g. "packed" which one's on your mind?I think we all know that “double dabble” is the best binary to bcd algorithm for processors with no multiply and limited memory, but what is the best algorithm for processors with a single-cycle multiply and no shortage of memory?
Not familiar with that processor.32 bits, on a cortex M4
Yes, the UMULL or SMULL instruction does that, but when it does division, it doesn’t give you quotient and remainder, just quotient, and it takes a multiply and subtract to get the remainderNot familiar with that processor.
When you do a 32 bit integer multiply, does it result in a 64-bit result stored in two registers?
OK, so printf does that already, as does sprintf et al. - %dBinary to BCD is required when you need to display a binary value in a human recognizable format.
Have you ever looked at how heavy the footprint of printf() is?OK, so printf does that already, as does sprintf et al. - %d
Yes. That's what started this all off. The program "evolved" and ended up with four different functions to display numbers in decimal in four different formats, and I decided it needed "tidying".If you want to use the library, you would sprintf( ) to a string and then send the string to the LCD.
However, I agree. I would write my own functions.