Java Binary to Hex bin2Hex(byte[] b)

Here you can find the source of bin2Hex(byte[] b)

Description

bin Hex

License

Open Source License

Declaration

public final static String bin2Hex(byte[] b) 

Method Source Code

//package com.java2s;

public class Main {
    private static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
            'E', 'F' };

    public final static String bin2Hex(byte[] b) {
        return bin2Hex(b, 0, b.length);
    }/*from ww  w .  j a v a  2 s  .c  om*/

    public final static String bin2Hex(byte[] b, int pos, int length) {
        if (length < 0 || length > b.length || pos + length > b.length)
            throw new ArrayIndexOutOfBoundsException();
        StringBuilder sb = new StringBuilder(length * 2);
        for (int i = pos, size = pos + length; i < size; i++) {

            sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]);
            sb.append(HEX_DIGITS[b[i] & 0x0f]);
        }
        return sb.toString();
    }
}

Related

  1. bin2hex(byte[] arr)
  2. bin2Hex(byte[] bin)
  3. bin2hex(final byte[] b)
  4. bin2hex(final byte[] base)
  5. bin2hex(int digit)