Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To Hex String and back...

 
Marcus Laubli
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • 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 ]
 
M Beck
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic