Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.