String to hex conversion
 CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

Thread: String to hex conversion

1. Junior Member
Join Date
Aug 2010
Posts
2

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

2. Elite Member
Join Date
Jun 1999
Location
Eastern Florida
Posts
3,783

Re: String to hex conversion

One way is to use the Integer.toHexString() method.
Extract a char from the String and use the method

3. Elite Member Power Poster
Join Date
Aug 1999
Location
UK
Posts
10,163

Re: String to hex conversion

Originally Posted by imdondon
Kindly write the complete program
Thanks
No.

Thanks.

You do it 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 ).

All truths are easy to understand once they are discovered; the point is to discover them...
G. Galilie
Last edited by dlorde; August 11th, 2010 at 06:29 PM.

4. Junior Member
Join Date
Aug 2010
Posts
2

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

5. Elite Member
Join Date
Jun 1999
Location
Eastern Florida
Posts
3,783

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.
__________________

6. Elite Member Power Poster
Join Date
Aug 1999
Location
UK
Posts
10,163

Re: String to hex conversion

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

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)