Java Hex Calculate toHexString(byte[] bytes)

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

Description

toHexString.

License

Apache License

Parameter

Parameter Description
bytes an array of byte.

Return

a object.

Declaration

public static final String toHexString(byte[] bytes) 

Method Source Code

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

public class Main {
    /**/* w  ww.j  a va  2 s. c  o m*/
     * <p>toHexString.</p>
     *
     * @param bytes an array of byte.
     * @return a {@link String} object.
     */
    public static final String toHexString(byte[] bytes) {
        StringBuilder ret = new StringBuilder(64);
        for (byte each : bytes) {
            String hexStr = Integer.toHexString(each >= 0 ? each : (256 + each));
            if (hexStr.length() == 1) {
                ret.append("0");
            }
            ret.append(hexStr);
        }
        return ret.toString();
    }
}

Related

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