public static String bytesToBinHex(byte[] data,int nStartPos,int nNumOfBytes){
  StringBuilder sbuf=new StringBuilder();
  sbuf.setLength(nNumOfBytes << 1);
  int nPos=0;
  for (int nI=0; nI < nNumOfBytes; nI++) {
    sbuf.setCharAt(nPos++,HEXTAB[(data[nI + nStartPos] >> 4) & 0x0f]);
    sbuf.setCharAt(nPos++,HEXTAB[data[nI + nStartPos] & 0x0f]);
  }
  return sbuf.toString();
}

public static String bytesToBinHex ( byte [ ] data , int nStartPos , int nNumOfBytes ) { StringBuilder sbuf = new StringBuilder ( ) ; sbuf . setLength ( nNumOfBytes << 1 ) ; int nPos = 0 ; for ( int nI = 0 ; nI < nNumOfBytes ; nI ++ ) { sbuf . setCharAt ( nPos ++ , HEXTAB [ ( data [ nI + nStartPos ] > > 4 ) & 0x0f ] ) ; sbuf . setCharAt ( nPos ++ , HEXTAB [ data [ nI + nStartPos ] & 0x0f ] ) ; } return sbuf . toString ( ) ; }
converts a byte array to a binhex string
