printf problem

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I'm trying to print out hex codes with a preceding "0x" and always using two bytes after that. What is the correct switch to use in printf?

printf_P (PSTR ("\r\n'%02x'\r\n"),0x01); produces:
'01'

printf_P (PSTR ("\r\n'%02#x'\r\n"),0x01); produces:
'0x1'

Any ideas?

Cheers,
Børge

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use 0x%02x.

I think %#02x works, too, but it produces a "00" on some systems iff the value is 0.
Offhand, I'm not sure about avr-libc.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.