CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2010
    Posts
    2

    Lightbulb 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. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: String to hex conversion

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

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

    Re: String to hex conversion

    Quote Originally Posted by imdondon View Post
    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.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  4. #4
    Join Date
    Aug 2010
    Posts
    2

    Question 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. #5
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

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

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

    Re: String to hex conversion

    Quote Originally Posted by imdondon View Post
    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
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Tags for this Thread

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

Featured