aspose file tools
The moose likes Beginning Java and the fly likes String to Binary? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "String to Binary?" Watch "String to Binary?" New topic
Author

String to Binary?

Travis Gn
Greenhorn

Joined: Sep 11, 2003
Posts: 19
I am trying to take a sting ie. "hello" and convert it to binary. I think if I broke it down into char and used digit() it may work? But I don't understand the syntax to use digit() or maybe it's forDigit()? Any other pointers please include. Any help greatly appriciated.


I need more help!
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
Travis,
Are you sure this kind of conversion a meaningful task ?
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
Travis,
You break the String down into an array of char by calling getChar() on it. You can then get the int value of each char using the Integer.toBinaryString() method to convert each char to a binary String representation as in the following code fragment:

Is this what you are trying to do ?
It's unclear from your post exactly what you mean by "convert it to binary".
Character.digit() converts a char that represents a digit in some radix to the equivalent int.
kktec
SCJP, SCWCD, SCJD


kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: String to Binary?
 
Similar Threads
octal , hexa question
int to hexadecimal
14 ^ 23
ascii to binary conversion
Binary in java - guide me