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 support@ccsinfo.com

int32 to hex

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



Joined: 19 Oct 2004
Posts: 40

View user's profile Send private message

int32 to hex
PostPosted: Mon May 26, 2008 3:18 am     Reply with quote

hi
I am trying to use sprintf to convert a int32 variable to a hex using

char DS[7];
int32 variable
sprintf(DS,"%06x",variable)

If for instance the variable=771 I get 000003 instead of 000303. For any number I have 0000. If the variable is int it is not a problem but If
the format is int32 I think %06x is not correct.
Does anyone know the solution?
Thanks
Ttelmah
Guest







PostPosted: Mon May 26, 2008 3:28 am     Reply with quote

You need to add an 'L'.
%x formats are to convert integers. To convert a 'long' (int16, or int32), the format is %Lx. What you are seeing is only the low 8bits of your value, since you don't have the 'L'. %06Lx, should give what you want.

Best Wishes
angel



Joined: 19 Oct 2004
Posts: 40

View user's profile Send private message

thanks
PostPosted: Mon May 26, 2008 4:33 am     Reply with quote

thanks Ttelmah it works
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