Convert character to ASCII numeric value in java
To convert a character to its ASCII numeric value in Java, you can use the charAt
method of the String
class and the intValue
method of the Character
class.
Here's an example of how you can do this:
char c = 'A';
int asciiValue = (int) c;
Alternatively, you can use the getNumericValue
method of the Character
class:
char c = 'A';
int asciiValue = Character.getNumericValue(c);
This will convert the character 'A'
to its ASCII numeric value, which is 65.
Note that the ASCII numeric value of a character represents the integer value of the character in the ASCII encoding. The ASCII encoding assigns a unique integer value to each printable and non-printable character in the ASCII table.