Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Java Hex to String

Posted on 2007-11-19
6
Medium Priority
?
18,216 Views
Last Modified: 2013-12-22
Hello

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

41424344

Example output:
ABCD

Thanks from now!
0
Comment
Question by:CSecurity
6 Comments
 
LVL 26

Expert Comment

by:ksivananth
ID: 20311849
I don't think you can do that! there should be some delemeter between each char representation...
0
 
LVL 17

Author Comment

by:CSecurity
ID: 20311859
Hex maximum length is 2
0
 
LVL 17

Author Comment

by:CSecurity
ID: 20311861
and for hex with length 1 there will be zero before it
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Accepted Solution

by:
Bart Cremers earned 2000 total points
ID: 20311909
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 20311970

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

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20311987
String s = new String(new BigInteger("41424344", 16).toByteArray()));
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question