Alex Rivera | Logout

Binary to text in Java

Asked 2010-11-18T04:34:39.987
10

I have a String with binary data in it (1110100) I want to get the text out so I can print it (1110100 would print "t"). I tried this, it is similar to what I used to transform my text to binary but it's not working at all:

    public static String toText(String info)throws UnsupportedEncodingException{
        byte[] encoded = info.getBytes();
        String text = new String(encoded, "UTF-8");
        System.out.println("print: "+text);
        return text;
    }

Any corrections or suggestions would be much appreciated.

Thanks!

Edit
Report

1 Answer

0

Look at the parseInt function. You may also need a cast and the Character.toString function.

answered 2010-11-18T04:37:45.980

Your Answer