Java Hex Calculate toHexString(byte[] byteArray)

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

Description

Converts a byte array to hex string without leading 0x.

License

Apache License

Parameter

Parameter Description
byteArray A byte array to convert to a hex string.

Return

A string representing the hex representation of the input.

Declaration

public static String toHexString(byte[] byteArray) 

Method Source Code

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

public class Main {
    /**/*from  ww  w  . j  a  v  a2  s.com*/
     * Hex characters for use producing human readable strings.
     */
    public static final String hexChars = "0123456789ABCDEF";

    /**
     * Converts a byte array to hex string without leading 0x.
     *
     * @param byteArray A byte array to convert to a hex string.
     * @return A string representing the hex representation of the input.
     */
    public static String toHexString(byte[] byteArray) {
        if (byteArray == null) {
            return null;
        }
        final StringBuilder sb = new StringBuilder(2 + 2 * byteArray.length);
        for (final byte b : byteArray) {
            sb.append(hexChars.charAt((b & 0xF0) >> 4)).append(hexChars.charAt((b & 0x0F)));
        }
        return sb.toString();
    }
}

Related

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