?
Solved

Java Hex to String

Posted on 2007-11-19
6
Medium Priority
?
18,200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

718 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