Here you can find the source of bytesToHexString(byte[] bytes)
public static String bytesToHexString(byte[] bytes)
//package com.java2s; public class Main { /**//w w w . j ava 2 s. c om * Calculate the SHA1 id of the given string. */ private static final int HEX_RADIX = 16; private static final int BITS_PER_NIBBLE = 4; public static String bytesToHexString(byte[] bytes) { if (bytes == null) { return null; } StringBuffer result = new StringBuffer(bytes.length * 2); for (int i = 0; i < bytes.length; i++) { result.append(Character.forDigit( (bytes[i] & 0xF0) >> BITS_PER_NIBBLE, HEX_RADIX)); result.append(Character.forDigit(bytes[i] & 0x0F, HEX_RADIX)); } return result.toString(); } }