File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Conversion of String to binary ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Conversion of String to binary ?" Watch "Conversion of String to binary ?" New topic
Author

Conversion of String to binary ?

chetan dhumane
Ranch Hand

Joined: Jan 07, 2009
Posts: 629

How to convert string to binary and again back to original string ?

Thanks in advance.


http://www.androcid.com/
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14108
    
  16

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: 38363
    
  23
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: 629

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: 38363
    
  23
If your String contains spaces = or + (etc) you will have to parse it with a compiler parser, otherwise it would be an impossible task.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Conversion of String to binary ?