• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

To Hex String and back...

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm in the middle of a muddle....

I'm trying to create a small class that will give me tools to convert a String to a string of hex numbers, then take that string of hex numbers and return to a normal string.

Here's my code:




Right now, I'm just worried about the toHexString method and the hexToString method. In my main method, I first convert with:



then I want to return to my original string with



Here's my output..



As you can see, the result from hexToString does not result in the abc123 that went in at the beginning.

I think the problem is the casting of rawInt to (char), but I don't know how to change this!

Please help.
[ May 11, 2005: Message edited by: Marcus Laubli ]
 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in hexToString, you seem to be doing:

but will that take into account the radix of the intString? your example is "abc123", which appears to come out to a hexadecimal string without any of the letters A-F in it, but it's still base 16, correct?
 
Marcus Laubli
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just figured out what's happening. I get Hex 61 for 'a', which is the first letter in the string. Then when I convert 61 back, I'm hitting decimal 61, which is '='... oops.

How can I change this? I'm guessing that I really only need 00 - 7F in hex.
 
Marcus Laubli
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just changed the output in the first message because I ran it through twice. Sorry for the confusion!
 
M Beck
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, looking through the API docs for the Integer class, i notice there's a different version of parseInteger that seems like it might be useful in this case...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic