2010-08-18 04:25 AM
using printf to display a buffer in hex format
2011-05-17 06:10 AM
2011-05-17 06:10 AM
Hi ubiali,
I have tried ''%2x'' and ''%1X'' and I got 800 for 0x08 and 1f00 for 0x1f. What could be the solution ? Is related to stdlib ? Thanks for the help ! Thanks & Regards, MCU Lüfter2011-05-17 06:10 AM
Hi,
I just tried unsigned int buffer[] = {0x08, 0x1f}; void main(void) { printf(''%02x %02x'', buffer[0], buffer[1]); } and it prints 08 1f with the Cosmic stm8 compiler. Regards, Luca2011-05-17 06:10 AM
2011-05-17 06:10 AM
Hi ubiali,
Thanks for your test but my buffer is unit8_t type and when I print I am getting ''800'' and ''1f00''. I think that ''%02x'' works for unsigned int (16 bits) and not for uint8_t (8 bits). What could you suggest ? By curiosity, I have tried another compiler and I have found that it prints with %2.2 (and I am not sure that this is what should be). I am really thankful. Regards, MCU Lüfter