Java Binary to Hex binToHex(byte[] bytes)

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

Description

bin To Hex

License

Apache License

Declaration

public static char[] binToHex(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 char[] binToHex(byte[] bytes) {
        return binToHex(bytes, 0, bytes.length);
    }/*from   ww w  .j  a  v a  2 s  .  c o m*/

    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. binaryToHex(char[] binaryStr)
  2. binaryToHex(int binary)
  3. BinaryToHexString(byte[] bytes)
  4. binaryToHexString(String binaryValue)
  5. binToHex(byte[] bin)
  6. binToHex(byte[] data)
  7. binToHex(String bin)
  8. binToHex(String sBinString)
  9. binToHexString(byte[] bytes)