code: protected static String toHex(final byte[] bin) {
          if (bin == null || bin.length == 0)
              return "";
  
          char[] buffer = new char[bin.length * 2];
  
          final char[] hex = "0123456789abcdef".toCharArray();
  
          // i tracks input position, j tracks output position
          for (int i = 0, j = 0; i < bin.length; i++)
          {
              final byte b = bin[i];
              buffer[j++] = hex[(b >> 4) & 0x0F];
              buffer[j++] = hex[b & 0x0F];
          }
          return new String(buffer);
      }
docs: encode binary to hex