code: public static String toHex(byte[] data, int off, int end) {
          //double size, two bytes (hex range) for one byte
          StringBuilder buf = new StringBuilder(data.length * 2);
          if (end > data.length) {
              end = data.length;
          }
          for (int i = off; i < end; i++) {
              //don't forget the second hex digit
              if (((int)data[i] & 0xff) < 0x10) {
                  buf.append("0");
              }
              buf.append(Long.toString((int)data[i] & 0xff, 16).toUpperCase());
              if (i < end - 1) {
                  buf.append(" ");
              }
          }
          return buf.toString();
      }
docs: Returns a <tt>String</tt> containing unsigned hexadecimal
  numbers as digits.
  The <tt>String</tt> will coontain two hex digit characters
  for each byte from the passed in <tt>byte[]</tt>.<br>
  The bytes will be separated by a space character.
  
  @param data   the array of bytes to be converted into a hex-string.
  @param off    the offset to start converting from.
  @param end    the offset of the end of the byte array.
  
  @return the generated hexadecimal representation as <code>String</code>.