Skip to content

Instantly share code, notes, and snippets.

@alhazmy13
Last active March 15, 2016 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alhazmy13/21a80c1a831efbaef350 to your computer and use it in GitHub Desktop.
Save alhazmy13/21a80c1a831efbaef350 to your computer and use it in GitHub Desktop.
Binary & String converter
//==============================================================
// 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