Here you can find the source of bytesToHex(byte[] data)
public static String bytesToHex(byte[] data)
//package com.java2s; public class Main { public static String bytesToHex(byte[] data) { return bytesToHex(data, 0, data.length); }/*from w w w . j ava2 s . c o m*/ public static String bytesToHex(byte[] data, int offset, int length) { if (length <= 0) { return ""; } StringBuilder hex = new StringBuilder(); for (int i = offset; i < offset + length; i++) { hex.append(String.format(" %02X", data[i] % 0xFF)); } hex.deleteCharAt(0); return hex.toString(); } }