Java Hex Calculate toHexadecimal(final byte[] in)

Here you can find the source of toHexadecimal(final byte[] in)

Description

to Hexadecimal

License

Apache License

Declaration

public static String toHexadecimal(final byte[] in) 

Method Source Code

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

public class Main {

    public static String toHexadecimal(final byte[] in) {
        return toHexadecimal(in, 0, in.length);
    }/*www.  j  a v  a2s .c o  m*/

    public static String toHexadecimal(byte[] in, int ini, int len) {
        final StringBuffer sb = new StringBuffer();
        char c;
        final int limit = (ini + len < in.length ? ini + len : in.length);

        for (int i = ini; i < limit; i++) {
            // First nibble
            c = (char) ((in[i] >> 4) & 0xf);
            if (c > 9) {
                c = (char) ((c - 10) + 'a');
            } else {
                c = (char) (c + '0');
            }
            sb.append(c);

            // Second nibble
            c = (char) (in[i] & 0xf);
            if (c > 9) {
                c = (char) ((c - 10) + 'a');
            } else {
                c = (char) (c + '0');
            }
            sb.append(c);
        }

        return sb.toString();
    }
}

Related

  1. toHexAddress(long address)
  2. toHexaDecimal(byte[] bytesToConvert)
  3. toHexadecimal(byte[] digest)
  4. toHexadecimal(byte[] digest)
  5. toHexadecimal(final byte[] array)
  6. toHexadecimal(final byte[] message)
  7. toHexadecimealString(byte[] data, int length, boolean uppercase)
  8. toHexArray(byte[] binary)
  9. toHexaString(byte[] data)