Here you can find the source of toHexString(byte input[])
public static String toHexString(byte input[])
//package com.java2s; //License from project: Apache License public class Main { public static String toHexString(byte input[]) { return toHexString(input, input.length); }//from w w w . j ava 2s . co m public static String toHexString(byte input[], int limit) { int i = 0; if (input == null || input.length <= 0) return null; char lookup[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; char[] result = new char[(input.length < limit ? input.length : limit) * 2]; while (i < limit && i < input.length) { result[2 * i] = lookup[(input[i] >> 4) & 0x0F]; result[2 * i + 1] = lookup[(input[i] & 0x0F)]; i++; } return String.valueOf(result); } }