1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | public class string { static byte parser(String temp) { int i=0, sum=0; while(i<8) { sum= (int) (sum*2+temp.charAt(i++)-'0'); System.out.println(sum); } return (byte) sum; } static String ex(String temp) { byte str[]=new byte[2]; str[0]=(byte)parser(temp.substring(0, 8)); str[1]=(byte)parser(temp.substring(8, 16)); return new String(str); } public static void main(String[] args) { String str="1011010011111010"; System.out.println(ex(str)); } } |
Direct link: https://paste.plurk.com/show/ezpa3rjPN38nuspelbBy