Java Byte to Hex String byteToHexString(byte[] data)

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

Description

Convert the given byte array to its hex representation.

License

Apache License

Parameter

Parameter Description
data The byte array to be converted.

Return

The hex representation of the given byte array

Declaration

public static String byteToHexString(byte[] data) 

Method Source Code

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

public class Main {
    /**/*from   w ww  .j  a v  a 2  s  . c o  m*/
     * Convert the given byte array to its hex representation.
     * From <a href="http://stackoverflow.com/questions/2817752/java-code-to-convert-byte-to-hexadecimal">http://stackoverflow.com/questions/2817752/java-code-to-convert-byte-to-hexadecimal</a>
     *
     * @param data The byte array to be converted.
     *
     * @return The hex representation of the given byte array
     */
    public static String byteToHexString(byte[] data) {
        StringBuilder sb = new StringBuilder();
        for (byte b : data) {
            sb.append(String.format("%02X", b));
        }

        return sb.toString();
    }
}

Related

  1. byteToHexString(byte[] b)
  2. byteToHexString(byte[] b)
  3. byteToHexString(byte[] bytes)
  4. byteToHexString(byte[] bytes, int start, int end)
  5. byteToHexString(byte[] bytes, int start, int end)
  6. byteToHexString(final byte b)
  7. byteToHexString(final byte b)
  8. byteToHexString(final byte inbyte)
  9. byteToHexString(int b)