View previous topic :: View next topic |
Author |
Message |
MarcosAmbrose
Joined: 25 Sep 2006 Posts: 38 Location: Adelaide, Australia
|
How do I printf an int32 |
Posted: Fri Mar 16, 2007 5:34 pm |
|
|
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
|
|
|
MarcosAmbrose
Joined: 25 Sep 2006 Posts: 38 Location: Adelaide, Australia
|
|
Posted: Fri Mar 16, 2007 5:58 pm |
|
|
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?
|
|
|
Guest
|
|
Posted: Fri Mar 16, 2007 6:00 pm |
|
|
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
|
|
Posted: Fri Mar 16, 2007 6:03 pm |
|
|
%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 |
|
|
|