Java tutorial
//package com.java2s; public class Main { private final static char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'a', 'b', 'c', 'd', 'e', 'f' }; public static String bytesToHexes(byte[] bytes) { if (bytes == null || bytes.length == 0) { return null; } StringBuffer sb = new StringBuffer(); for (int i = 0; i < bytes.length; i++) { sb.append(byteToHexDigits(bytes[i])); } return sb.toString(); } public static String byteToHexDigits(byte b) { int n = b; if (n < 0) n += 256; int d1 = n / 16; int d2 = n % 16; return "" + HEX_DIGITS[d1] + HEX_DIGITS[d2]; } }