Java Hex Calculate toHex(byte[] text)

Here you can find the source of toHex(byte[] text)

Description

Utility method which converts a byte[] to a hexadecimal string of characters, in lower case

License

Open Source License

Parameter

Parameter Description
text The array to convert

Return

A string representation

Declaration

public static String toHex(byte[] text) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from  w ww. j a v  a2 s . c om*/
    * The array used for conversion to hexadecimal
     */
    public final static char[] HEX_ARRAY = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b',
            'c', 'd', 'e', 'f' };

    /**
     * Utility method which converts a byte[] to a hexadecimal string of characters, in lower case
     *
     * @param text The array to convert
     * @return A string representation
     */
    public static String toHex(byte[] text) {
        StringBuffer buffer = new StringBuffer();

        for (int i = 0; i < text.length; i++) {
            buffer.append(HEX_ARRAY[0x0f & (text[i] >> 4)]);
            buffer.append(HEX_ARRAY[0x0f & text[i]]);
        }

        return buffer.toString();
    }
}

Related

  1. toHex(byte[] raw)
  2. toHex(byte[] raw)
  3. toHex(byte[] raw)
  4. ToHex(byte[] src)
  5. toHex(byte[] src)
  6. toHex(byte[] v)
  7. toHex(byte[] val)
  8. toHex(byte[] val, int start, int len)
  9. toHex(byte[] value)