Here you can find the source of toHex(byte[] input)
static String toHex(byte[] input)
//package com.java2s; //License from project: Apache License public class Main { static String toHex(byte[] input) { StringBuilder sb = new StringBuilder(); for (byte b : input) { int i = (b >> 4) & 0x0f; if (i > 9) { sb.append((char) (i + 55)); } else { sb.append((char) (i + 48)); }// www .j a va2 s. c o m i = b & 0x0f; if (i > 9) { sb.append((char) (i + 55)); } else { sb.append((char) (i + 48)); } } return sb.toString(); } /** * if (len(input)<offset+length) throw toHex(input[offset,input.length]) * * @param input * @param offset * @param length max length * @return */ static String toHex(byte[] input, int offset, int length) { byte[] bytes = getSomeByte(input, offset, length); return toHex(bytes); } /** * @param input * @param offset * @param length * @return */ static byte[] getSomeByte(byte[] input, int offset, int length) { byte[] bytes = new byte[length]; System.arraycopy(input, offset, bytes, 0, length); return bytes; } }