Solved

Java Hex to String

Posted on 2007-11-19
6
18,163 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 13

Accepted Solution

by:
Bart Cremers earned 500 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now