This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reversible String to Number convertor

 
Vijay Kashyap
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a requirement for generating reversible String to Number Conversion utility. Can somebody supply me the pointers to go about bulding this.

I am stating an example to clarify the need:

For input String 'Java Ranch' I need to generate a unique number which should be able to convert back to 'Java Ranch' string.

TIA,
Vijay
 
Arun Bommannavar
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess would be HashMap.

Regards
Arun
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it all depends on how much you would like to complicate it. One simple way would be to get bytes from the String and convert them to a number, and then conver the number back to bytes and get the String, provided that you can use the same encoding for both operations all the time.



Anohter way could be encryption. See Java Almanac for an example.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic