View previous topic :: View next topic |
Author |
Message |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
Stuck on 16 bit printf issue |
Posted: Fri May 06, 2016 11:13 am |
|
|
I am returning to PICs from a few years in Arduinoland. I seem to be stuck on a trivial point. Printf only prints 8 bit numbers? This code:
Code: |
longCount = 0x1234;
printf("longCount => %4X", longCount);
printf(" highByte => %4X\n\r",longCount>>8); |
prints "0034" for longCount and 0012 for the high byte. I expected longCount to be "1234".
What am I doing wrong? _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1908
|
|
Posted: Fri May 06, 2016 11:56 am |
|
|
I think it's supposed to be LX instead of X when you're trying to pass/print a word. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri May 06, 2016 12:16 pm |
|
|
Using:
printf("longCount => %L4X", longCount);
gives:
*** Error 115 "main.c" Line 29(46,47): Printf format (%) invalid ::
where without the 'L' it compiles _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1908
|
|
Posted: Fri May 06, 2016 12:18 pm |
|
|
SherpaDoug wrote: | Using:
printf("longCount => %L4X", longCount);
gives:
*** Error 115 "main.c" Line 29(46,47): Printf format (%) invalid ::
where without the 'L' it compiles |
Did you try "%4LX" instead? |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri May 06, 2016 1:18 pm |
|
|
Ah! %4LX did it.
And %8LX works for int32 as well!
Thanks _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|