How to convert hexadecimal string to ASCII string in Java

1 Answer

0 votes
public class MyClass {
    public static String hex_to_ASCII(String hex) { 
        String ascii = ""; 
  
        for (int i = 0; i < hex.length(); i += 2) { 
            String s = hex.substring(i, i + 2); 
            char ch = (char)Integer.parseInt(s, 16); 
            ascii = ascii + ch; 
        } 
  
        return ascii;
    } 
    public static void main(String args[]) {
        System.out.println(hex_to_ASCII("61627A64")); 
    }
}


/*
run:

abzd

*/

 



answered Aug 10, 2019 by avibootz

Related questions

2 answers 159 views
2 answers 391 views
1 answer 170 views
1 answer 141 views
...