Java Byte Array to Hex bufferToHex(byte bytes[])

Here you can find the source of bufferToHex(byte bytes[])

Description

buffer To Hex

License

Open Source License

Declaration

private static String bufferToHex(byte bytes[]) 

Method Source Code

//package com.java2s;

public class Main {
    public static char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
            'f' };

    private static String bufferToHex(byte bytes[]) {
        return bufferToHex(bytes, 0, bytes.length);
    }/*  ww  w  . j a va 2  s  .  com*/

    private static String bufferToHex(byte[] bytes, int i, int length) {
        StringBuffer sb = new StringBuffer(2 * length);
        int k = i + length;
        for (int l = i; l < k; l++) {
            appendHexPair(bytes[l], sb);
        }
        return sb.toString();
    }

    private static void appendHexPair(byte b, StringBuffer sb) {
        char c0 = hexDigits[(b & 0xf0) >> 4];
        char c1 = hexDigits[b & 0x0f];
        sb.append(c0);
        sb.append(c1);
    }
}

Related

  1. bufferToHexString(byte[] buffer)
  2. bufferToHexString(byte[] data, int start, int length)
  3. bytes2Hex(byte bt)
  4. bytes2Hex(byte... values)