Google Answers Logo
View Question
 
Q: Convert hex string to readable string in Java ( No Answer,   0 Comments )
Question  
Subject: Convert hex string to readable string in Java
Category: Computers > Programming
Asked by: mrbananagrabber-ga
List Price: $10.00
Posted: 26 Jul 2006 06:55 PDT
Expires: 26 Jul 2006 07:54 PDT
Question ID: 749694
I am pulling values from a Windows registry .reg file. I have registry
values like this:
"SystemBiosVersion"=hex(7):44,00,45,00,4c,00,4c,00,20,00,20,00,20,00,2d,00,20,\
  00,37,00,00,00,50,00,68,00,6f,00,65,00,6e,00,69,00,78,00,20,00,52,00,4f,00,\
  4d,00,20,00,42,00,49,00,4f,00,53,00,20,00,50,00,4c,00,55,00,53,00,20,00,56,\
  00,65,00,72,00,73,00,69,00,6f,00,6e,00,20,00,31,00,2e,00,31,00,30,00,20,00,\
  41,00,30,00,34,00,00,00,00,00

I can strip away everything and I have the hex string:
440045004c004c002000200020002d0020037000000500068006f0065006e0069007800200052004f00d002000420049004f005300200050004c0055005300200056065007200730069006f006e00200031002e003100300020001003000340000000000

I want to convert this to a readable string in Java 5.0. I have a
suspicion that it is UTF-16LE. The readable string for the above
example should be: "DELL   - 7
Phoenix ROM BIOS PLUS Version 1.10 A04", but it doesn't seem to be
working when I try converting the string to bytes by calling
Integer.parseInt() on it, casting it to a byte array, and then make a
new string with the encoding.

An extra issue is that the string is a multi-string. The Windows
Registry Reference online defines a multi-string this way:

A sequence of null-terminated strings, terminated by an empty string (\0).

The following is an example:

String1\0String2\0String3\0LastString\0\0

The first \0 terminates the first string, the second to the last \0
terminates the last string, and the final \0 terminates the sequence.
Note that the final terminator must be factored into the length of the
string.

I would most like to just get a readable string, with the end goal of
having an array of each individual string in the multi-string. I'd
appreciate any help (even just getting the multi-string as one string
instead of a string array).

Clarification of Question by mrbananagrabber-ga on 26 Jul 2006 07:08 PDT
Here's the approach I'm taking right now. hex is the hex String:

byte[] bytes = new byte[hex.length() / 2];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2),
					16);
		}

//		try {
			String multi = new String(bytes);
			System.out.println(multi);

Clarification of Question by mrbananagrabber-ga on 26 Jul 2006 07:13 PDT
Woops. Ignore the above clarification. Here's my code:

String hex = "440045004c004c002000200020002d0020037000000500068006f0065006e0069007800200052004f00d002000420049004f005300200050004c0055005300200056065007200730069006f006e00200031002e003100300020001003000340000000000";

byte[] bytes = new byte[hex.length() / 2];
for (int i = 0; i < bytes.length; i++) {
   bytes[i] = (byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16);
}

String multi = new String(bytes);
System.out.println(multi);
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy