# String to hex conversion

• August 11th, 2010, 03:27 PM
imdondon
String to hex conversion
Hi,
I am a new programmer of java ,I want to convert a string into hex .Suppose if I have a value "A" then the program must convert it into "41",if I have "B" then it must be converted into "42".
Kindly write the complete program
Thanks
• August 11th, 2010, 06:14 PM
Norm
Re: String to hex conversion
One way is to use the Integer.toHexString() method.
Extract a char from the String and use the method
• August 11th, 2010, 06:26 PM
dlorde
Re: String to hex conversion
Quote:

Originally Posted by imdondon
Kindly write the complete program
Thanks

:rolleyes: No.

Thanks.

You do it :wave: Looks like you want the ASCII character value as a hex string.

Use the Integer.valueOf method to convert the character value of the String to it's decimal ASCII value. Then use the Integer.toString method with a radix argument to convert that decimal value to a string representation of its hex value (that's the long way round :D).

All truths are easy to understand once they are discovered; the point is to discover them...
G. Galilie
• August 12th, 2010, 01:32 PM
imdondon
Re: String to hex conversion
Would anybody please write the program of conversion "ABCD" into hex.
Actully I have tried alot but there come errors.So I will be highly thankfull if some body write a working program
Thanks
• August 12th, 2010, 01:41 PM
Norm
Re: String to hex conversion
Did you try this:
Extract a char from the String (see String methods) and use the Integer.toHexString() method
A char will convert to an int for the method call above.
Loop over the length of the String.
__________________
• August 12th, 2010, 06:16 PM
dlorde
Re: String to hex conversion
Quote:

Originally Posted by imdondon
Would anybody please write the program of conversion "ABCD" into hex.
Actully I have tried alot but there come errors.So I will be highly thankfull if some body write a working program
Thanks

You usually have to pay to have someone write code for you on demand. There are other sites for buying code. This forum is about helping you to write the code yourself.

If you want help with errors, explain what is going wrong and post the code and the full text of the error messages.

The value of a prototype is in the education it gives you, not in the code itself...
A. Cooper