Java Binary to Hex binToHexString(byte[] bytes)

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

Description

bin To Hex String

License

Apache License

Declaration

public static String binToHexString(byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

    public static String binToHexString(byte[] bytes) {
        return new String(binToHex(bytes));
    }/*from  www.  j av a 2s.  com*/

    public static String binToHexString(byte[] bytes, int offset, int len) {
        return new String(binToHex(bytes, offset, len));
    }

    public static char[] binToHex(byte[] bytes) {
        return binToHex(bytes, 0, bytes.length);
    }

    public static char[] binToHex(byte[] bytes, int offset, int len) {
        final char[] sb = new char[len * 2];
        final int end = offset + len;
        int index = 0;
        final char[] hexs = hex;
        for (int i = offset; i < end; i++) {
            byte b = bytes[i];
            sb[index++] = (hexs[((b >> 4) & 0xF)]);
            sb[index++] = hexs[((b) & 0xF)];
        }
        return sb;
    }
}

Related

  1. binToHex(byte[] bin)
  2. binToHex(byte[] bytes)
  3. binToHex(byte[] data)
  4. binToHex(String bin)
  5. binToHex(String sBinString)