• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 18274
  • Last Modified:

Java Hex to String

Hello

I want to convert a Hex String to String.
Example input:

41424344

Example output:
ABCD

Thanks from now!
0
CSecurity
Asked:
CSecurity
1 Solution
 
ksivananthCommented:
I don't think you can do that! there should be some delemeter between each char representation...
0
 
CSecurityAuthor Commented:
Hex maximum length is 2
0
 
CSecurityAuthor Commented:
and for hex with length 1 there will be zero before it
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Bart CremersJava ArchitectCommented:
Here's a method for use with fixed lengths. Usage:

    hexToString("41424344", 2)
    public static String hexToString(String input, int groupLength) {
        StringBuilder sb = new StringBuilder(input.length() / groupLength);
 
        for (int i = 0; i < input.length() - groupLength + 1; i += groupLength) {
            String hex = input.substring(i, i + groupLength);
            sb.append((char) Integer.parseInt(hex, 16));
        }
 
        return sb.toString();
    }

Open in new window

0
 
CEHJCommented:

String s = new String(new BigInteger("41424344").toByteArray()));

Open in new window

0
 
CEHJCommented:
String s = new String(new BigInteger("41424344", 16).toByteArray()));
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now