SHARE
TWEET

Untitled

a guest Oct 21st, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
  2.     public static String bytesToHex(byte[] bytes) {
  3.         char[] hexChars = new char[bytes.length * 2];
  4.         for (int j = 0; j < bytes.length; j++) {
  5.             int v = bytes[j] & 0xFF;
  6.             hexChars[j * 2] = HEX_ARRAY[v >>> 4];
  7.             hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
  8.         }
  9.         return new String(hexChars);
  10.     }
  11.     public static byte[] hexStringToByteArray(String s) {
  12.         int len = s.length();
  13.         byte[] data = new byte[len / 2];
  14.         for (int i = 0; i < len; i += 2) {
  15.             data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
  16.                     + Character.digit(s.charAt(i+1), 16));
  17.         }
  18.         return data;
  19.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top