using printf to display a buffer in hex format
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2010-08-18 4:25 AM
Posted on August 18, 2010 at 13:25
using printf to display a buffer in hex format
This discussion is locked. Please start a new topic to ask your question.
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 6:10 AM
Posted on May 17, 2011 at 15:10 I think replacing'' %04X'' with ''%2x'' should work (haven't tried though) Luca
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 6:10 AM
Posted on May 17, 2011 at 15:10
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üfterOptions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 6:10 AM
Posted on May 17, 2011 at 15:10
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, LucaOptions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 6:10 AM
Posted on May 17, 2011 at 15:10 cast to int when calling printf: printf(''%02x %02x'', (int)buffer[0], (int)buffer[1]); Regards, Luca
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 6:10 AM
Posted on May 17, 2011 at 15:10
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