Jun 22, 2008 at 8:27pm
How do I get the ASCII code for a char type variable?
And How do I convert ASCII code back to a character?
Jun 22, 2008 at 8:32pm
You can use a cast to convert it to int from char and the oppoosite.
Here is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
using namespace std;
int main(){
char ascii;
int numeric;
cout << "Give character: ";
cin >> ascii;
cout << "Its ascii value is: " << (int) ascii << endl;
cout << "Give a number to convert to ascii: ";
cin >> numeric;
cout << "The ascii value of " << numeric << " is " << (char) numeric;
return 0;
}
|
Last edited on Jun 22, 2008 at 8:32pm
Jun 23, 2008 at 1:28am
Dear Mitsakos:
Thank you very much for the prompt reply... I will try this...
Jul 9, 2008 at 4:26am
its just the dec value of ascii code... how 'bout the hex value???
Jul 10, 2008 at 2:03am
Thanks simo110!!! thank you very much!!! mwah!!! XD