I need to convert a String value into Binary format. For Example: String str = "Java"; now i want to get it in binary format.how could i do this? any one could please help me!
-
3What is binary for you? What do you want to do with the value after?Alexandre Lavoie– Alexandre Lavoie2013-06-12 06:51:42 +00:00Commented Jun 12, 2013 at 6:51
-
1In what form do you want that binary representation? A ByteBuffe? A String of 1's and 0's?Michael Lawrie– Michael Lawrie2013-06-12 06:51:54 +00:00Commented Jun 12, 2013 at 6:51
-
i wnat to get binary represenattion for the string "Java" in 1 byte.user2451783– user24517832013-06-12 07:17:57 +00:00Commented Jun 12, 2013 at 7:17
-
@user2451783 give an example, this is vague.Alexandre Lavoie– Alexandre Lavoie2013-06-12 07:51:00 +00:00Commented Jun 12, 2013 at 7:51
Add a comment
|
4 Answers
Try this,
byte[] infoBin = null;
infoBin = "Java".getBytes("UTF-8");
for (byte b : infoBin) {
System.out.println("c:" + (char) b + "-> "
+ Integer.toBinaryString(b));
}
See this link : String to binary output in Java
1 Comment
user2451783
Thanks for your quick reply.But it is giving 40 bits binary value for the String "Java";But i want to get 8 bit binary value for this String "Java".How could i do?