Here you can find the source of byteToHexstr(byte[] b, boolean space)
public static String byteToHexstr(byte[] b, boolean space)
//package com.java2s; public class Main { public static String byteToHexstr(byte[] b, boolean space) { StringBuilder toHex = new StringBuilder(); for (int i = 0; (null != b) && (i < b.length); i++) { if (space) { toHex.append(' '); }//from www .ja v a 2 s . c o m char hi = Character.forDigit((b[i] >> 4) & 0x0F, 16); char lo = Character.forDigit(b[i] & 0x0F, 16); toHex.append(Character.toUpperCase(hi)); toHex.append(Character.toUpperCase(lo)); } return toHex.toString(); } }