Java Hex Calculate toHexString(final byte[] array)

Here you can find the source of toHexString(final byte[] array)

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(final byte[] array) 

Method Source Code

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

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

    public static String toHexString(final byte[] array) {
        return toStringHex(array, 0, array.length);
    }//from   www  . jav a 2 s.  c  o  m

    public static String toStringHex(final byte[] array, final int off, final int len) {
        final char[] result = new char[len << 1];
        final int end = off + len;

        for (int i = off, b, j = 0; i < end; i++) {
            b = array[i] & 0xff;
            result[j++] = HEX_ARRAY[b >> 4];
            result[j++] = HEX_ARRAY[b & 0x0f];
        }

        return new String(result);
    }
}

Related

  1. toHexString(final byte b)
  2. toHexString(final byte b)
  3. toHexString(final byte hex)
  4. toHexString(final byte value)
  5. toHexString(final byte[] arr)
  6. toHexString(final byte[] b)
  7. toHexString(final byte[] bs)
  8. toHexString(final byte[] bs, final char[] myDigits)
  9. toHexString(final byte[] buffer)