Here you can find the source of toHexString(byte[] bytes)
public static String toHexString(byte[] bytes)
//package com.java2s; //License from project: Apache License public class Main { private static final int BYTE_MASK = 0xFF; public static String toHexString(byte[] bytes) { if (bytes != null) { StringBuilder hexString = new StringBuilder(); for (byte b : bytes) { String hex = Integer.toHexString(b & BYTE_MASK); if (hex.length() == 1) { hexString.append('0'); }// ww w. ja v a 2 s. c om hexString.append(hex); } return hexString.toString(); } else { return null; } } }