1

Input in is converted correctly. output for in is gd`x]jef But in1 is not getting output. because in1 is the binary string of UTF-8 text of ���GF

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class Tostr {


public void toStrng(String input) throws UnsupportedEncodingException
{
    //String input = "1111010 1011001 1100010"; // Binary input as String

   // byte[] code = input.getBytes("UTF-8");
   // byte ptext[] = input.getBytes(Charset.forName("UTF-8"));
  //  String in = new String(ptext, Charset.forName("UTF-8"));

    StringBuilder sb = new StringBuilder(); // Some place to store the chars

    Arrays.stream( input.split(" ")).forEach(s -> sb.append((char) Integer.parseInt(s, 2)));


    String output = sb.toString();
    System.out.println(output);

    //return output;
}

public static void main(String arg[]) throws UnsupportedEncodingException
{
    String in="1100111 1100100 1100000 1111000 1011101 1101010 1100101 1100110";
    String in1="11111111111111111111111111101111 11111111111111111111111110111111 11111111111111111111111110111101 101 10101 11111111111111111111111111101111 11111111111111111111111110111111 11111111111111111111111110111101 11111111111111111111111111101111 11111111111111111111111110111111 11111111111111111111111110111101 1000111 1000110 101";
    Tostr ts= new Tostr();
    ts.toStrng(in);        
    ts.toStrng(in1);

}     
}

I need to get the output on in1 as ���GF please help me to correct the code the exception occurs is NumberFormatException.forInputString

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.