Java Byte Array to Hex bytesToHex(byte[] bs, int off, int length)

Here you can find the source of bytesToHex(byte[] bs, int off, int length)

Description

bytes To Hex

License

Open Source License

Declaration

public static final String bytesToHex(byte[] bs, int off, int length) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static final String bytesToHex(byte[] bs, int off, int length) {
        StringBuffer sb = new StringBuffer(length * 2);
        bytesToHexAppend(bs, off, length, sb);
        return sb.toString();
    }/*from  ww  w  .j a  v a 2  s. c o m*/

    public static final String bytesToHex(byte[] bs) {
        return bytesToHex(bs, 0, bs.length);
    }

    public static final void bytesToHexAppend(byte[] bs, int off, int length, StringBuffer sb) {
        sb.ensureCapacity(sb.length() + length * 2);
        for (int i = off; i < (off + length) && i < bs.length; i++) {
            sb.append(Character.forDigit((bs[i] >>> 4) & 0xf, 16));
            sb.append(Character.forDigit(bs[i] & 0xf, 16));
        }
    }
}

Related

  1. bytesToHex(byte[] b)
  2. bytesToHex(byte[] b)
  3. bytesToHex(byte[] b)
  4. bytesToHex(byte[] b, int offset, int length)
  5. bytesToHex(byte[] binary)
  6. bytesToHex(byte[] bt)
  7. bytesToHex(byte[] buf)
  8. bytesToHex(byte[] bytes)
  9. bytesToHex(byte[] bytes)