| Author |
Conversion of String to binary ?
|
chetan dhumane
Ranch Hand
Joined: Jan 07, 2009
Posts: 628
|
|
How to convert string to binary and again back to original string ?
Thanks in advance.
|
http://www.androcid.com/
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
People mean different things by "binary". What exactly do you mean here by "converting a String to binary"?
Class String has several getBytes() methods, but without knowing what exactly you mean with your question I can't tell if those do what you want.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
|
With the appropriate methods of the java.lang.Integer class.
|
 |
Venkata Kumar
Ranch Hand
Joined: Apr 16, 2008
Posts: 110
|
|
What does the string contain. Is it integer or binary value or anything else?
Check the Java API to convert string to integer and then to binary value.
|
SCJP 5.0, SCWCD 5, preparing for SCDJWS
|
 |
chetan dhumane
Ranch Hand
Joined: Jan 07, 2009
Posts: 628
|
|
The string can contain anything from characters to integer values and also special characters +, =, space etc.
I can convert it into binary string i.e. a string of 0s and 1s.
ex; String str="101";
now i want to convert it back to string .
|
 |
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
|
|
|
Use BinaryCodec of apache commons codec. If its not the assigment that expect you to implement the thing for yourself.
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
chetan dhumane wrote:
ex; String str="101";
now i want to convert it back to string .
Have a look at Integer.parseInt(String,int); method.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
|
If your String contains spaces = or + (etc) you will have to parse it with a compiler parser, otherwise it would be an impossible task.
|
 |
 |
|
|
subject: Conversion of String to binary ?
|
|
|