Created
April 7, 2013 11:03
-
-
Save RaffaeleSgarro/5330018 to your computer and use it in GitHub Desktop.
Print a hexdump of a string
This file contains hidden or 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
| 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