![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
julien lochen
Joined: 16 May 2008 Posts: 14
|
ascii value of a character |
Posted: Mon Jun 23, 2008 7:52 am |
|
|
Hello, what is the function to get the ascii value of a character, like
int get_ascii(A)
thanks, julien |
|
![](templates/subSilver/images/spacer.gif) |
milkman41
Joined: 16 Jun 2008 Posts: 30
|
|
Posted: Mon Jun 23, 2008 8:23 am |
|
|
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; |
|
![](templates/subSilver/images/spacer.gif) |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Mon Jun 23, 2008 8:34 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon Jun 23, 2008 2:57 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|