Hi,
How to convert a character to ASCII in C++?.
Regards,
Hi,
How to convert a character to ASCII in C++?.
Regards,
Please try this code!
Code:#include <iostream.h> #include <stdlib.h> int main() { int number; char letter; int option; cout<<"Convert ASCII numbers into characters and vice versa"; cout<<endl<<"[1] * ASCII -> ABC" <<endl<<"[2] * ABC -> ASCII" <<endl<<"[3] * EXIT"<<endl;; cin>>option; switch (option) //Detects the option { case 1: cout<<"Enter a number : "; cin >> number; //Inputs the number cout<<"The number you entered is : \""<<char(number)<<"\" in ASCII"<<endl; //Ouputs the same number in char break; case 2: cout<<"Enter a letter : "; cin >> letter; //Inputs the letter cout<<"The character you entered is : \""<<int(letter)<<"\" in ASCII"<<endl; //Outputs the same letter in int break; case 3: return 0; default: //If user chooses anything else besides options given cout<<"Invalid Option!"; system("PAUSE"); break; } system("PAUSE"); return 0; }
Here's what I've tried (I see now why this did not work...):
But this does not result in 94 but a byte with value 63...Code:string myInput = Convert.ToString(Convert.ToChar(710)); byte[] asBytes = Encoding.ASCII.GetBytes(myInput);
Here's a new try but it still does not work:
Code:byte[] bytes = Encoding.ASCII.GetBytes("ê");
Bookmarks