Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1.      public static void hexdump (String s) {
  2.          
  3.          byte[] data = null;
  4.          try { data = s.getBytes("us-ascii"); } catch (Exception x) { }
  5.          
  6.          String h = "", t = "";
  7.          int c = 16;
  8.          for (byte b : data) {
  9.              h += String.format("%02x ", b);
  10.              t += (b < 32 ? "." : String.format("%c", b));
  11.              if (-- c == 0) {
  12.                  System.out.printf(": %-48s  %-16s\n", h, t);
  13.                  c = 16;
  14.                  h = t = "";
  15.              }
  16.          }
  17.          if (c < 16)
  18.              System.out.printf(": %-48s  %-16s\n", h, t);
  19.          
  20.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement