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

Covert a hex value to decimal value

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



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

Covert a hex value to decimal value
PostPosted: Sat Sep 01, 2007 9:55 am     Reply with quote

The output of the LTC1298 sample programs give for example

Ch0: 2.500v = 8000h

this value must be 800h and i must be converted to dec.
How can i do this?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Sep 01, 2007 10:51 am     Reply with quote

atoi() requires the string to start with '0x'.
strtol() seems like a better choice.

You don't want to convert the last character? Then just replace it with a 0 when passing to strtol() so it becomes the end-of-string marker.

atoi() and strtol() are large functions because they are so versatile. If you are tight on memory you can have a look at axtoi(): http://www.ccsinfo.com/forum/viewtopic.php?p=679#679
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Sep 01, 2007 10:56 am     Reply with quote

A long int value must converted to a decimal value

Please give a sample code for converting a long int to decimal number
long int = 8000
after conversion the dec is than 2047
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Sep 01, 2007 11:35 am     Reply with quote

If have now this

Code:
convert_to_volts(data,volt_str);
   data=data>>4;
   lcd_gotoxy(1,2); printf(lcd_putc,"Ch0: %Sv %4LX",volt_str,data);


But the first value (volt_str) will not correct displayed
Why
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