+ 6

How to get a ascii value of the character??

please tell the program

27th Jun 2018, 3:48 PM
Saranya
Saranya - avatar
6 Answers
+ 8
in javaScript you have a special function .. charCodeAt()
27th Jun 2018, 5:18 PM
Prashanth Kumar
Prashanth Kumar - avatar
+ 6
Hello, Saranya ! There are a few ways to do this. Using char struct (to string and back again) string _stringOfA = char.ConvertFromUtf32(65); int _asciiOfA = char.ConvertToUtf32("A", 0); Simply casting the value (char and string shown) char _charA = (char)65; string _stringA = ((char)65).ToString(); Using ASCIIEncoding. This can be used in a loop to do a whole array of bytes var _bytearray = new byte[] { 65 }; ASCIIEncoding _asiiencode = new ASCIIEncoding(); string _alpha = _asiiencode .GetString(_newByte, 0, 1); You can override the type converter class, this would allow you to do some fancy validation of the values: var _converter = new ASCIIConverter(); string _stringA = (string)_converter.ConvertFrom(65); int _intOfA = (int)_converter.ConvertTo("A", typeof(int)); https://stackoverflow.com/questions/4648781/how-to-get-character-for-a-given-ascii-value https://stackoverflow.com/questions/22536095/how-to-get-a-character-ascii-value-in-a-integer-variable
27th Jun 2018, 3:51 PM
Alexander Sokolov
Alexander Sokolov - avatar
+ 3
there are different methods to do it in different languages. Some examples: C++ cout << int('A'); >>> 65 you can the change the value of character to get it's ASCII value. Python: print(ord('A')) >>> 65
27th Jun 2018, 4:03 PM
RZK 022
RZK 022 - avatar
+ 3
#include <stdio.h> int main() { for(char x = 'a'; x != 'z'+1; x++) { int nm = x; printf("\n %c : %d",x,nm); } return 0; } // That program prints the character and it's corresponding ASCII value, a-z
27th Jun 2018, 4:25 PM
RZK 022
RZK 022 - avatar
+ 2
You forget to say which language do you want... Anyway in C++ you can use a simple base cast operation: char c='\n'; // newline unsigned int i= (unsigned int)c; // 10
27th Jun 2018, 3:58 PM
KrOW
KrOW - avatar
+ 2
please tell the c program to print the ASCII value for a given character..
27th Jun 2018, 4:09 PM
Saranya
Saranya - avatar