• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Conversion of String to binary ?

 
chetan dhumane
Ranch Hand
Posts: 641
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to convert string to binary and again back to original string ?

Thanks in advance.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15482
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50189
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the appropriate methods of the java.lang.Integer class.
 
Venkata Kumar
Ranch Hand
Posts: 110
Firefox Browser Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
chetan dhumane
Ranch Hand
Posts: 641
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use BinaryCodec of apache commons codec. If its not the assigment that expect you to implement the thing for yourself.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50189
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your String contains spaces = or + (etc) you will have to parse it with a compiler parser, otherwise it would be an impossible task.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic