Here you can find the source of bytes2hex(byte[] bytes)
public static String bytes2hex(byte[] bytes)
//package com.java2s; //License from project: Apache License public class Main { public static String bytes2hex(byte[] bytes) { StringBuilder hex = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { byte b = bytes[i]; boolean negative = false; if (b < 0) negative = true;// w w w .j av a 2 s . c o m int bAbs = Math.abs(b); if (negative) bAbs = bAbs | 0x80; String temp = Integer.toHexString(bAbs & 0xFF); if (temp.length() == 1) { hex.append("0"); } hex.append(temp.toLowerCase()); } return hex.toString(); } }