how can I change a number from ASCII code to integer.
e.g. I want to different function can be chosen by typing 1, 2 or 3 in PC and the PIC read it through RS232. but the problem was:
when I typed '1' and got it through RS232 by getchar(). The '1' is stored as ASCII code 49, but I want to use '1' to classify cases..
so, I have to translate the ASCII code of '1' back to integer 1.
please tell me how. thanks
Ttelmah Guest
Posted: Wed May 10, 2006 4:43 am
If it is only a single digit, then just use:
VAL=(ASC_CHAR-'0');
For a complete 'string' (multiple characters), look at 'atoi'.
Best Wishes
luckyluke
Joined: 18 Apr 2006 Posts: 45
Posted: Wed May 10, 2006 3:04 pm
numbers begin from 48 (decimal for 0) to 57 (decimal for 9)
if you sbstract 48 from what you get with getchar() you will have the number
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