Here you can find the source of formatHEX(byte[] btValue, int iOffset, int iLength)
public static String formatHEX(byte[] btValue, int iOffset, int iLength)
//package com.java2s; //License from project: Apache License public class Main { public static String formatHEX(byte[] btValue, int iOffset, int iLength) { int iLastOffset = iOffset + iLength; if (btValue.length < iLastOffset || iLength < 1) return ""; StringBuffer value = new StringBuffer(); for (int i = iOffset; i < iLastOffset; i++) { byte l, h; h = (byte) ((btValue[i] & 0xF0) >>> 4); if (h < 10) h = (byte) ('0' + h); else// w w w.jav a2 s .c o m h = (byte) ('A' + h - 10); l = (byte) ((btValue[i] & 0x0F)); if (l < 10) l = (byte) ('0' + l); else l = (byte) ('A' + l - 10); value.append((char) h); value.append((char) l); } return value.toString(); } }