Java Hex Calculate toHexString(byte[] data)

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

Description

Turn a bytearray into a printable form, representing each byte in hex.

License

Open Source License

Parameter

Parameter Description
data the bytearray to stringize

Return

a hex-encoded printable representation of data

Declaration

public static String toHexString(byte[] data) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*w ww. j a  v  a  2 s .co m*/
     * Turn a bytearray into a printable form, representing
     * each byte in hex.
     *
     * @param data the bytearray to stringize
     * @return a hex-encoded printable representation of <code>data</code>
     */
    public static String toHexString(byte[] data) {
        StringBuffer sb = new StringBuffer(data.length * 2);
        for (int i = 0; i < data.length; ++i) {
            sb.append(Integer.toHexString((data[i] >> 4) & 15));
            sb.append(Integer.toHexString(data[i] & 15));
        }
        return sb.toString();
    }
}

Related

  1. toHexString(byte[] content, int len)
  2. toHexString(byte[] data)
  3. toHexString(byte[] data)
  4. toHexString(byte[] data)
  5. toHexString(byte[] data)
  6. toHexString(byte[] data)
  7. toHexString(byte[] data)
  8. toHexString(byte[] data)
  9. toHexString(byte[] data)