Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ASCII value at input word

Tags:

I have a character:

 char ch='A' 

Give me method which converts char to ASCII
or way which returns a ASCII NUMBER.

Output : 65

like image 387
Nikunj Patel Avatar asked Sep 16 '11 11:09

Nikunj Patel


People also ask

How do I get ASCII value in Word?

Choose Find from the Edit menu, or press Ctrl+F. In the Find What box, enter the text for which you want to search. To search for an ASCII character, enter a carat (^) followed by the three numbers representing the ASCII value of the character. For instance, to search for an uppercase A, you could enter ^065.

How do I get the ASCII value in Python?

To get ascii value of char python, the ord () method is used. It is in-built in the library of character methods provided by Python. ASCII or American Standard Code for Information Interchange is the numeric value that is given to different characters and symbols.

What is the ASCII value of A to Z?

Below are the implementation of both methods: Using ASCII values: ASCII value of uppercase alphabets – 65 to 90. ASCII value of lowercase alphabets – 97 to 122.


2 Answers

char ch='A';  System.out.println((int)ch); 
like image 198
Oliver Charlesworth Avatar answered Oct 17 '22 06:10

Oliver Charlesworth


There is a major gotcha associated with getting an ASCII code of a char value.

In the proper sense, it can't be done.

It's because char has a range of 65535 whereas ASCII is restricted to 128. There is a huge amount of characters that have no ASCII representation at all.

The proper way would be to use a Unicode code point which is the standard numerical equivalent of a character in the Java universe.

Thankfully, Unicode is a complete superset of ASCII. That means Unicode numbers for Latin characters are equal to their ASCII counterparts. For example, A in Unicode is U+0041 or 65 in decimal. In contrast, ASCII has no mapping for 99% of char-s. Long story short:

char ch = 'A'; int cp = String.valueOf(ch).codePointAt(0); 

Furthermore, a 16-bit primitive char actually represents a code unit, not a character and is thus restricted to Basic Multilingual Plane, for historical reasons. Entities beyond it require Character objects which deal away with the fixed bit-length limitation.

like image 36
Saul Avatar answered Oct 17 '22 07:10

Saul