Solved

Java Hex to String

Posted on 2007-11-19
6
18,191 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

624 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