java - Binary to String trouble -


Hello I am trying to write a program that covers the binary entered by a user in a string of text. I've hit one type of blockage, I can get my program to hide "01110110" for "v", but once I tried to do something like "0110100001101001", it gives me the word "hi" Gives the symbols instead. Below is the source code that I am using. P.S. Thanks, you still help in trying to get an understanding of Java.

  import javax.swing.JOptionPane; Public class binaryettext {public static zero main (string ARG []) {string b = joptionpan.SonyputDialog (blank, "enter binary"); Int charCode = integer.centant (b, 2); String k = new character ((four) charcoda) .string (); JOptionPane.showMessageDialog (zero, K); }}    

If your string exceeds 8 bits, then you have to break it Each 8-bit segment is independently down and parsed, such as:

  int charCode; String k = ""; String b = joppenpen.showinputdialog (empty, "enter binary"); While (B-Length = 8) {Charcoda = Integer. PRISIN (B.SbString (0, 8), 2); K + = new character ((four) charcoal) .toString (); B = b.substring (8); } If (b.length ()> gt; 0) Attempts can handle any trailing bits that are charcoal = integer. Equal (B, 2) can be left; K + = new character ((four) charcoal) .toString (); } YojanaPen Show message dialog (empty, k);    

Comments