How do I get the ASCII code for a char type variable?
And How do I convert ASCII code back to a character?
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
Dear Mitsakos:
Thank you very much for the prompt reply... I will try this...
its just the dec value of ascii code... how 'bout the hex value???
Thanks simo110!!! thank you very much!!! mwah!!! XD