CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Stuck on 16 bit printf issue

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

Stuck on 16 bit printf issue
PostPosted: Fri May 06, 2016 11:13 am     Reply with quote

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: 1907

View user's profile Send private message

PostPosted: Fri May 06, 2016 11:56 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 06, 2016 12:16 pm     Reply with quote

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: 1907

View user's profile Send private message

PostPosted: Fri May 06, 2016 12:18 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 06, 2016 1:18 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group