The ASCII table is arranged so that the value of the character '9' is nine greater than the value of '0'; the value of the character '8' is eight greater than the value of '0'; and so on.

So you can get the int value of a decimal digit char by subtracting '0'.

char x = '9';
int y = x - '0'; // gives the int value 9
Answer from khelwood on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-program-to-convert-char-to-int
Java Program to Convert Char to Int - GeeksforGeeks
String.valueOf() can convert the character into a String, and Integer.parseInt() can then convert that numeric string into an int. Syntax: int value = Integer.parseInt(String.valueOf(ch)); Java ยท
Published: August 18, 2026
Discussions

converting ch to int java
int int1 = (int)ch; should do it, I don't know what part of your code isn't working like it's supposed to you could also try - int a=Character.getNumericValue(ch); More on reddit.com
๐ŸŒ r/CodingHelp
4
3
November 30, 2021
Converting characters to integers in Java - Stack Overflow
That is a utility method that converts characters to integers (as in, the character '5' into the integer 5). That is not the same as a cast (which converts the character '5' into the integer 53). ... The point is that casting does not return the digit's numeric value. Those two operations do two different things. ... Save this answer. ... Show activity on this post. ... The java... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Convert int to char in place.
Are you sure that is ok? If the number is greater than 0 prints the number in reverse order and appends an extra 0 at the end, and for negatives just doesn't work. This code prints the digits in the expected order and works for negatives: https://godbolt.org/z/oE7z9EMa4 More on reddit.com
๐ŸŒ r/cpp_questions
5
1
January 12, 2022
Example to Convert int to char in Java
https://www.scientecheasy.com/2022/05/char-to-int-in-java.html/ More on reddit.com
๐ŸŒ r/JavaProgramming
1
4
July 15, 2024
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ java types โ€บ convert char to int in java with examples
Convert Char to Int in Java with examples
December 3, 2024 - In Java weโ€™ve got two types of typecasting, explicit and implicit. Implicit can only be done if we convert the variable from "larger" to "smaller" type (say, from int to long). If we want to convert a variable of type char to int data type, most often we need to get its equivalent value from the ASCII table.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ char to int in java
Char to Int in Java - Scaler Topics
May 23, 2024 - American Standard Code for Information Interchange is an encoding format used to store characters on a computer, it is a 7- bit character set containing 128 characters. In Java programming language we have implicit typecasting, i.e if we store the value of a smaller datatype to a variable of the larger datatype, then the value is automatically converted.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ core java โ€บ convert between int and char in java
Convert Between int and char in Java | Baeldung
January 16, 2024 - We can easily check this by casting the char value to int: ... ASCII code is a subset of the Unicode encoding, representing mostly the English alphabet. Letโ€™s say we have an int variable with value 7 and we want to convert it to its char counterpart โ€˜7โ€˜. We have a few options to do this.
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ examples โ€บ char-to-int-conversion
Java Program to convert char type variables to int | Programiz
March 14, 2024 - We can also use the getNumericValue() method of the Character class to convert the char type variable into int type.
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2019 โ€บ 04 โ€บ java-char-to-int-conversion
Java Convert char to int with examples
September 11, 2022 - In the following example we are assigning char values to integer variables without any typecasting. Compiler automatically doing the conversion here, this only applies when we are assigning a smaller data type to larger data type else we have to do explicit type casting. public class JavaExample{ public static void main(String args[]){ char ch = 'A'; char ch2 = 'Z'; int num = ch; int num2 = ch2; System.out.println("ASCII value of char "+ch+ " is: "+num); System.out.println("ASCII value of char "+ch2+ " is: "+num2); } }
Find elsewhere
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 404152 โ€บ java โ€บ convert-character-integer
convert character to integer (Beginning Java forum at Coderanch)
July 16, 2006 - do not store a 5 anywhere; you store 53 or more precisely 0000_0000_0011_0101. You don't convert chars to integers at all; chars always are integers (see this Javaโ„ข Language Specification section).
๐ŸŒ
Reddit
reddit.com โ€บ r/codinghelp โ€บ converting ch to int java
r/CodingHelp on Reddit: converting ch to int java
November 30, 2021 -

i have an assignment where we have to import a file of letters and convert these to ascii numbers where each even number is a colour and each odd is the background. I am struggling on how to convert ch to an int.

heres my code so far

import sheffield.*;
import java.util.Arrays;

public class Assignment2Practice {
       public static void main(String args[]) {
       	   
       	EasyReader fileInput= new EasyReader("duck.txt"); // read in duck file
        String duckText = fileInput.readString(); // convert to string variable
        
        char [][] duckArray = new char [130][130];
       
        for (int 	j =0; (j <130); j++) {
			for (int i=0; (i < 130); i++){
			char ch = duckText.charAt(i); // j[1], v[2]
			int int1= ch;
			
			int int2 = (int) ch;
			
			duckArray[j][i] = ch;
		
			}
	   }
	   System.out.println(Arrays.deepToString(duckArray));
	   }
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-to-convert-char-to-int-in-java
How to Convert Char to Int in Java?
August 17, 2023 - In this approach, char is converted to int by subtracting ASCII value of ?0' to ASCII value by given char.
๐ŸŒ
Edureka
edureka.co โ€บ blog โ€บ java-char-to-int
Java Char to Int | How to Convert Char to Int with Examples | Edureka
September 6, 2024 - In Java, the value contained in ... true for char to int conversion. Converting a char to an int is equivalent to finding the ASCII value of the given character....
๐ŸŒ
Software Testing Help
softwaretestinghelp.com โ€บ home โ€บ java โ€บ how to convert char to int in java [with examples]
How To Convert Char To Int In Java [With Examples]
April 1, 2025 - If we print the value of โ€˜bโ€™, then you will see console prints โ€˜49โ€™. This is because when we assign char variable value โ€˜aโ€™ to int variable โ€˜bโ€™, we actually retrieve the ASCII value of โ€˜1โ€™ which is โ€˜49โ€™. In the following sample Java program, letโ€™s see how to convert character to int through implicit typecast i.e.
๐ŸŒ
Tutorial Gateway
tutorialgateway.org โ€บ java-program-to-convert-char-to-int
Java Program to Convert Char to Int
August 25, 2026 - This example accepts the user input character and converts it to int. package NumPrograms; import java.util.Scanner; public class CharToInt1 { private static Scanner sc; public static void main(String[] args) { sc= new Scanner(System.in); System.out.print("Please Enter any Character = "); char ch = sc.next().charAt(0); int i = ch; System.out.println("The ASCII Value of " + ch + " = " + i); System.out.format("The ASCII Value of %c = %d", ch, i); } }
๐ŸŒ
JanBask Training
janbasktraining.com โ€บ home โ€บ how to convert char to int in java
How to Convert Char to Int in Java | Char Array to Int Array
November 5, 2018 - In this tutorial, you will basically learn how to convert the char data type to int in Java. The value contained in one data type can be converted to other based on conversion requirements, the same holds true for char to int conversion as well. Here is a simple example where char is converted to int with cast keyword.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java array โ€บ convert char array to int array in java
Convert Char Array to Int Array in Java | Baeldung
January 8, 2024 - This method offers a straightforward and concise way to return the int value of the given character.
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ java โ€บ examples โ€บ convert char type variables to int
Java Program to convert char type variables to int | Vultr Docs
December 16, 2024 - Discover how these conversions leverage Javaโ€™s built-in functionalities to seamlessly transition between data types, perfect for handling ASCII values and performing character arithmetic. Define a character variable. Convert the character to its corresponding ASCII integer representation using explicit casting.
๐ŸŒ
DaniWeb
daniweb.com โ€บ programming โ€บ software-development โ€บ threads โ€บ 333846 โ€บ convert-char-to-int
java - convert char to int [SOLVED] | DaniWeb
December 26, 2010 - You can simply assign a char to an int without needing to convert anything. ... This kind of code, that assumes US ASCII 7 bit coding, has no place in Java, which is UNICODE.