Hi,
I have problem with zero padding.
Here is my example code. I am using MCUXpresso IDE.
PRINTF("0x%04X ", buf);
The result is in the picture attached.
Best regards,
Syamil
Hi @mohd_
In this case, this is the behaviour of the PRINTF function.
if the number for the left padding is greather than the number to be printed, the PRINTF function will pad blank spaces.
Please, take a look at the below snapshot:
https://mcuxpresso.nxp.com/api_doc/dev/116/group__debugconsole.html
I hope this could help you!
If you have any comment of further question, let me know!
All the best,
Diego
Hi @diego_charles ,
Thank you for the information!
Hello Diego,
That is true the row above in the table states that a 0 prefix replaces space with zero padding and the format give was "%02X", as would be the case with standard C printf formatting.
Might this be a size optimization option to trimming down the set of formatting variants supported?
@mohd_: Have you considered rolling your own simple zero-extended tracing function as a workaround? Below is one such straightforward and entirely untested implementation
void PrintZeroExtended(uint32_t value, uint32_t radix, int32_t width) {
char buffer[sizeof "01234567"];
char *textptr = &buffer[sizeof buffer];
*--textptr = '\0';
do {
*--textptr = "0123456789ABCDEF"[value % radix];
value /= radix;
} while(--width >= 0 || value);
PRINTF("%s", textptr);
}
Regards,
Johan