Convert Int to ASCII in Java
- Get ASCII by Using Int to Char Conversion in Java
-
Get ASCII by Using
Character.toString()
in Java -
Get ASCII by Using
Character.forDigit()
in Java

This tutorial introduces how to convert an integer to ASCII code in Java.
In Java, int is a primitive data type that is used to store numeric values. It can be signed and unsigned. In comparison, the ASCII(American Standard Code for Information Interchange) is a code used by the computer system internally. Each keyboard key has a unique ASCII code. In Java, if we want to access/display ASCII code of any integer value, we can use several approaches such as converting int to char or using the Character.toString()
method.
Here, we will learn to get an ASCII code of any integer value in Java. So, let’s start with some examples.
Get ASCII by Using Int to Char Conversion in Java
This is the easiest approach where we just need to cast the integer value to char, and the value will get converted into ASCII value. See the example below.
public class SimpleTesting{
public static void main(String[] args){
int a = 97;
System.out.println("int value : "+a);
char ch = (char)a;
System.out.println("ASCII Value : "+ch);
}
}
Output:
int value : 97
ASCII Value : a
Get ASCII by Using Character.toString()
in Java
We can use the toString()
method of Character class that returns ASCII code as a String. It is good if we want to get the result as a string.
public class SimpleTesting{
public static void main(String[] args){
int a = 97;
System.out.println("int value : "+a);
String str = Character.toString(a);
System.out.println("ASCII Value : "+str);
}
}
Output:
int value : 97
ASCII Value : a
Get ASCII by Using Character.forDigit()
in Java
This is another solution where we can get an ASCII value by using the forDigit()
method of the Character
class. This method takes two arguments: the first is an integer value, and the second is a radix value. The radix is a base value of a number system such as 2, 8, 10, 16, etc. To get the ASCII value of a decimal value, use radix(base) 10.
public class SimpleTesting{
public static void main(String[] args){
int a = 97;
System.out.println("int value : "+a);
char ch1 = Character.forDigit(5, 10);
char ch2 = Character.forDigit(15, 16);
System.out.println("ASCII Value : "+ch1);
System.out.println("ASCII Value : "+ch2);
}
}
Output:
int value : 97
ASCII Value : 5
ASCII Value : f
Related Article - Java Integer
- Handle Integer Overflow and Underflow in Java
- Reverse an Integer in Java
- Convert Int to Binary in Java
- The Max Value of an Integer in Java
- Minimum and Maximum Value of Integer in Java
- Convert Integer to Int in Java