Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert a string to integer

 
Arun R. S. Chandran
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,

I wish to convert a strig to an integer and viceversa.

For Eg: A pure string "ARUN"- I wish to convert this to an integer.
And by converting that integer to string , I wish to get the same string
"ARUN"

Can anybody give me a proper solution for this?

Please help me if it is possible, because I am stuck in a project by this problem....

-ARUN
 
Mike Simmons
Ranch Hand
Posts: 3077
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it depends on what you mean by "integer". An int, in Java, has a maximum possible value. That means there's a finite number of values that can possibly be represented. Same for a long. How many possible different Strings are there? Unless you limit the length of the possible Strings, I think there is an infinite number. So an int or long cannot possibly represent all possible values. But there may be other data types that can (hint: check the java.math package in the API).

I would say that any possible String can be converted into a series of bytes. And any possible series of bytes can be converted into an integer (but not necessarily an int or long) - as long as you've got enough memory. Think about how you might do this.
 
Arun R. S. Chandran
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friend..

The string length is limited, we created in such a way. Because these are already existing shop names. These are fixed.
Now can you please help me how can I convert this one?

-ARUN
 
kranthi chamarthi
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to do this conversion? Is it for some kind of security purpose? If that is the case then you can search for sncryption algorithms in google.
For example a simple encryption algorithm is Substitution. If you use this for string "abc" you will get "123" (1-a,2-b,3-c). Hope this may be useful
 
Arun R. S. Chandran
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your reply,

But it's not security purpose. It's for sending data to a RTP. So RTP cant understand the string data. So I have to convert it to int. And when RTP sending some data in integer format I have to convert this to string for Display purpose.
That's the problem I am facing here..

-ARUN
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic