Here you can find the source of toHex(byte[] dBytes)
private static String toHex(byte[] dBytes)
//package com.java2s; //License from project: Apache License public class Main { private static String toHex(byte[] dBytes) { char[] hex = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; StringBuffer back = new StringBuffer(); for (int i = 0; i < dBytes.length; ++i) { int d = dBytes[i]; if (d < 0) { d = 256 + d;/*ww w . jav a 2 s . co m*/ } int a = d / 16; int c = d % 16; back.append(hex[a]).append(hex[c]); } return back.toString(); } }