Here you can find the source of toHex(byte[] value)
private static String toHex(byte[] value)
//package com.java2s; /*//from w w w . j a v a2s.co m * Copyright 2000-2013 Enonic AS * http://www.enonic.com/license */ public class Main { /** * Hex characters. */ private final static char[] HEX_CHARS = "0123456789ABCDEF".toCharArray(); /** * Return value as hex. */ private static String toHex(byte[] value) { char[] chars = new char[value.length * 2]; for (int i = 0; i < value.length; i++) { int a = (value[i] >> 4) & 0x0F; int b = value[i] & 0x0F; chars[i * 2] = HEX_CHARS[a]; chars[i * 2 + 1] = HEX_CHARS[b]; } return new String(chars); } /** * Return value as hex. */ public static String toHex(short value) { byte[] bytes = new byte[2]; bytes[0] = (byte) ((value >> 8) & 0xFF); bytes[1] = (byte) (value & 0xFF); return toHex(bytes); } /** * Return value as hex. */ public static String toHex(int value) { byte[] bytes = new byte[4]; bytes[0] = (byte) ((value >> 24) & 0xFF); bytes[1] = (byte) ((value >> 16) & 0xFF); bytes[2] = (byte) ((value >> 8) & 0xFF); bytes[3] = (byte) (value & 0xFF); return toHex(bytes); } /** * Return value as hex. */ public static String toHex(long value) { byte[] bytes = new byte[8]; bytes[0] = (byte) ((value >> 56) & 0xFF); bytes[1] = (byte) ((value >> 48) & 0xFF); bytes[2] = (byte) ((value >> 40) & 0xFF); bytes[3] = (byte) ((value >> 32) & 0xFF); bytes[4] = (byte) ((value >> 24) & 0xFF); bytes[5] = (byte) ((value >> 16) & 0xFF); bytes[6] = (byte) ((value >> 8) & 0xFF); bytes[7] = (byte) (value & 0xFF); return toHex(bytes); } }