Last active
March 15, 2016 11:29
-
-
Save alhazmy13/21a80c1a831efbaef350 to your computer and use it in GitHub Desktop.
Binary & String converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================== | |
// Binary To String | |
//============================================================== | |
public static String int2str( String s ) { | |
String[] ss = s.split( " " ); | |
StringBuilder sb = new StringBuilder(); | |
for ( int i = 0; i < ss.length; i++ ) { | |
sb.append( Character.toString((char)Long.parseLong( ss[i], 2 ) )); | |
} | |
return sb.toString(); | |
} | |
//============================================================== | |
// String to Binary | |
//============================================================== | |
public static String str2int(String s){ | |
String binary = ""; | |
for ( int i = 0; i < s.length(); i++ ) { | |
binary+= Integer.toBinaryString(s.charAt(i))+" "; | |
} | |
return binary; | |
} | |
//============================================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment