Java tutorial
//package com.java2s; public class Main { public static String byte2HexStrSpace(byte[] b, int length) { String stmp = ""; StringBuilder sb = new StringBuilder(""); for (int n = 0; n < length; n++) { stmp = Integer.toHexString(b[n] & 0xFF); sb.append((stmp.length() == 1) ? "0" + stmp : stmp); sb.append(" "); } return sb.toString().toUpperCase().trim(); } }