Skip to content

Convert character to ASCII numeric value in java

To convert a character to its numeric value in Java, you can simply cast the char to an int. In Java, the char type stores Unicode code points (UTF-16), and casting it to an int returns the underlying numeric value. For standard ASCII characters, this value matches the ASCII code.

Here's an example of how you can do this:


java
char c = 'A';
int asciiValue = (int) c;

This will convert the character 'A' to its numeric value, which is 65.

Note that the numeric value of a char represents its Unicode code point. The ASCII encoding assigns a unique integer value to each printable and non-printable character in the ASCII table, and these values are a subset of the Unicode standard.

Dual-run preview — compare with live Symfony routes.