Java tutorial
//package com.java2s; public class Main { public static String toHex(byte[] data) { String ret = null; if (data != null && data.length > 0) { StringBuilder sb = new StringBuilder(); for (byte b : data) { int v = b & 0x0FF; String hexString = Integer.toHexString(v); if (v > 0x0F) { sb.append(hexString); } else { sb.append('0').append(hexString); } } ret = sb.toString(); } return ret; } }