How to convert an ASCII character into a hex value in Java

1 Answer

0 votes
public class Main {
    public static void main(String[] args) {
        char asciiChar = 'A'; 
        
        int asciiValue = (int) asciiChar; // Convert to ASCII value
        String hexValue = Integer.toHexString(asciiValue); // Convert to hex
        
        System.out.println("The hexadecimal value of '" + asciiChar + "' is: 0x" + hexValue);
    }
}




/*
run:

The hexadecimal value of 'A' is: 0x41

*/

 



answered Dec 1, 2024 by avibootz

Related questions

1 answer 132 views
1 answer 119 views
1 answer 136 views
1 answer 129 views
2 answers 146 views
1 answer 110 views
...