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

How do I printf an int32

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



Joined: 25 Sep 2006
Posts: 38
Location: Adelaide, Australia

View user's profile Send private message

How do I printf an int32
PostPosted: Fri Mar 16, 2007 5:34 pm     Reply with quote

I want to printf a 32 bit variable in hex (but decimal will do) but I can't figure out the printf formatting string. Is an unsigned long int the same as an int32?
Code:

   int8 My8bitVar;
   int32 My32bitVar;

   My8bitVar=0x5A;
   My8bitVar=0xAABBA52B

   printf("Int8 Var = %X",My8bitVar)
   printf("Int32 Var = %what goes here?",My32bitVar)


....Thanks,
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 16, 2007 5:47 pm     Reply with quote

See my post in this thread. It has sample code to display values
larger than a byte.
http://www.ccsinfo.com/forum/viewtopic.php?t=27832&highlight=int16+int32+printf
MarcosAmbrose



Joined: 25 Sep 2006
Posts: 38
Location: Adelaide, Australia

View user's profile Send private message

PostPosted: Fri Mar 16, 2007 5:58 pm     Reply with quote

Thanks for that...
So the "%lu" string works for both 16 and 32 bit variable. Is that correct?

Regarding the other question, Is an "unsigned long int" the same as an int32?

PCM programmer wrote:
See my post in this thread. It has sample code to display values
larger than a byte.
http://www.ccsinfo.com/forum/viewtopic.php?t=27832&highlight=int16+int32+printf
Guest








PostPosted: Fri Mar 16, 2007 6:00 pm     Reply with quote

Quote:
Is an "unsigned long int" the same as an int32?

No, unsigned long is the same as unsigned int16.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 16, 2007 6:03 pm     Reply with quote

%LU works for int16 and int32.

In CCS, a 'long' is a 16-bit variable. You have to use 'int32' to declare
a 32-bit variable.

See page 23 in the CCS manual. (page 33 in the Acrobat reader)
See the section on "Basic and Special types":
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
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