Java Hex Calculate toHexString(byte[] byteArray)

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

Description

Takes a byte array and returns it HEX representation.

License

Open Source License

Parameter

Parameter Description
byteArray the byte array.

Return

the HEX representation.

Declaration

public static String toHexString(byte[] byteArray) 

Method Source Code

//package com.java2s;

public class Main {
    /**// w  w w  . ja  v  a2  s . co m
     * Takes a byte array and returns it HEX representation.
     * 
     * @param byteArray
     *            the byte array.
     * @return the HEX representation.
     */
    public static String toHexString(byte[] byteArray) {

        if (byteArray != null && byteArray.length != 0) {

            StringBuilder builder = new StringBuilder(byteArray.length * 3);
            for (int i = 0; i < byteArray.length; i++) {
                builder.append(String.format("%02X", 0xFF & byteArray[i]));

                if (i < byteArray.length - 1) {
                    builder.append(' ');
                }
            }
            return builder.toString();
        } else {
            return "--";
        }
    }
}

Related

  1. toHexString(byte[] buf, int offset, int len)
  2. toHexString(byte[] buffer)
  3. toHexString(byte[] byteArray)
  4. toHexString(byte[] byteArray)
  5. toHexString(byte[] byteArray)
  6. toHexString(byte[] byteArray)
  7. toHexString(byte[] byteArray, boolean withSpaces)
  8. toHexString(byte[] byteArray, int offset, int size)
  9. toHexString(byte[] byteArray, String delim)