Skip to content

Instantly share code, notes, and snippets.

@RaffaeleSgarro
Created April 7, 2013 11:03
Show Gist options
  • Select an option

  • Save RaffaeleSgarro/5330018 to your computer and use it in GitHub Desktop.

Select an option

Save RaffaeleSgarro/5330018 to your computer and use it in GitHub Desktop.
Print a hexdump of a string
package stackoverflow;
public class Hexdump {
public static void main(String[] args) {
// This is mocked. Get the actual filename
String filename = "Qwertypsadfksadf";
// Log the hexdump
System.out.println(hexdump(filename));
}
public static String hexdump(String str) {
StringBuilder builder = new StringBuilder();
String separator = "";
for (char c : str.toCharArray()) {
builder.append(separator).append(Integer.toHexString(c));
separator = " ";
}
return builder.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment