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

HELP!! how to convert CHAR to LONG INT

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







HELP!! how to convert CHAR to LONG INT
PostPosted: Wed Apr 21, 2004 2:19 am     Reply with quote

new user's question,
how to convert "Char" data type into "Long Int" data type?

thanks in advance!!
Ttelmah
Guest







Re: HELP!! how to convert CHAR to LONG INT
PostPosted: Wed Apr 21, 2004 2:38 am     Reply with quote

beg wrote:
new user's question,
how to convert "Char" data type into "Long Int" data type?

thanks in advance!!

Cast.
Conversions like this are 'semi automatic'. You can just use:
long int fred;
char chr;

fred=chr;

However if you want to force arithmetic to use the 'long int' equivalent, rather than being done using the char type, and then converted at the end, use the C 'cast', like:

fred=(long int)chr * 10;

Which forces 'chr' to be converted into a long int, before being multiplied by 10 in this example.

Best Wishes
DragonPIC



Joined: 11 Nov 2003
Posts: 118

View user's profile Send private message

atoi()
PostPosted: Wed Apr 21, 2004 11:38 am     Reply with quote

unless you are converting a ASCII # to a number. Then you would use atoi() or , if not a string of characters, mask off the high nibble of char byte.

Code:
char chr = '9';  //hex 0x39
long num;


num = chr & 0x0F;

//if hex

num = chr;
if (num > 0x39)
{
num &= 0x0F;
num += 0x09;
}
else
num &= 0x0F;

I'm sure you can find other more simple ways to do it.
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