Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String to Binary?

 
Travis Gn
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
chi Lin
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Travis,
Are you sure this kind of conversion a meaningful task ?
 
Ken Krebs
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic