Here you can find the source of bufferToHexString(byte[] data, int start, int length)
public static String bufferToHexString(byte[] data, int start, int length)
//package com.java2s; //License from project: Open Source License public class Main { public static String bufferToHexString(byte[] data, int start, int length) { int i;//from ww w. j a v a 2 s.c o m int myStop; StringBuilder sb = new StringBuilder(); //byte [] subArray = Arrays.copyOfRange(a, 4, 6); myStop = (length > data.length) ? data.length : length; for (i = start; i < start + myStop; i++) { sb.append(String.format("%02x ", data[i])); } return sb.toString(); } }