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

ascii value of a character

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



Joined: 16 May 2008
Posts: 14

View user's profile Send private message

ascii value of a character
PostPosted: Mon Jun 23, 2008 7:52 am     Reply with quote

Hello, what is the function to get the ascii value of a character, like

int get_ascii(A)

thanks, julien
milkman41



Joined: 16 Jun 2008
Posts: 30

View user's profile Send private message

PostPosted: Mon Jun 23, 2008 8:23 am     Reply with quote

I believe you can convert a character to an integer just by adding (int) before the character

ex:
int i;
char c;

i = (int)c;
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Jun 23, 2008 8:34 am     Reply with quote

Just use single quotes

int i;
i = 'A';

The compiler will do the rest.
you can also use it to retrieve ASCII codes for other things
'\r'
'\n'
etc.

type conversion should not be required in this case.
Ttelmah
Guest







PostPosted: Mon Jun 23, 2008 2:57 pm     Reply with quote

In fact there is no conversion.
'A' is a representation, we sometimes place on a byte containing the number 65.
The PIC itself, knows nothing (internally), about 'ASCII'. It receives the byte 65, and if asked to display it on an LCD, it the display generator on this, that turns the number into an 'A'. 'Char', is just an alternative name for an int8.
How it is output by the PIC, depends totally on what format you use in the output routine. So:
Code:

Char value;

value=getc(); //Assume 'A' arrives here.

printf("Char %c, decimal %d, hex %2x\n\r",value,value,value);
//Displays on a receiving terminal, Char A, decimal 65, hex 41

value+=32;
//Adds 32 to 65, to give 97. Note dealing with a number
printf("Char %c\n\r",value);
//Displays Char a - now lower case...


Best Wishes
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