Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert ASCII code (0-255) to its corresponding character?

Tags:

java

ascii

People also ask

What character is ASCII 255?

The ASCII character 255 is actually a non-breaking space, or NBSP!

What is the range of ASCII value for 0 to 9 characters?

The ASCII characters are numbered from 0 to 255. The chart below shows their designation in hexadecimal numbers. The ASCII characters are numbered from 00 to FF in hexadecimal. Note that 0 to 9 are the same in both numbering systems.

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.


Character.toString ((char) i);


System.out.println((char)65); would print "A"


String.valueOf(Character.toChars(int))

Assuming the integer is, as you say, between 0 and 255, you'll get an array with a single character back from Character.toChars, which will become a single-character string when passed to String.valueOf.

Using Character.toChars is preferable to methods involving a cast from int to char (i.e. (char) i) for a number of reasons, including that Character.toChars will throw an IllegalArgumentException if you fail to properly validate the integer while the cast will swallow the error (per the narrowing primitive conversions specification), potentially giving an output other than what you intended.


int number = 65;
char c = (char)number;

it is a simple solution