Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 18229
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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