Java tutorial
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); public class Main { private static final String HEX = "0123456789ABCDEF"; public static String bytesToHex(byte[] b) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < b.length; i++) { sb.append(byteToHex(b[i])).append(" "); } return sb.toString(); } public static String byteToHex(byte b) { int high = (b & 0xF0) >> 4; int low = (b & 0x0F); return "" + HEX.charAt(high) + HEX.charAt(low); } }