Java Formatter Usage byteArray2Hex(final byte[] hash)

Here you can find the source of byteArray2Hex(final byte[] hash)

Description

Converts an input byte array to a hex encoded String.

License

Apache License

Parameter

Parameter Description
input Byte array to hex encode

Return

Hex encoded String of the input byte array

Declaration

private static String byteArray2Hex(final byte[] hash) 

Method Source Code

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

import java.util.Formatter;

public class Main {
    /**/*  w w  w  .  j a va  2  s.c om*/
     * Converts an input byte array to a hex encoded String.
     *
     * @param input Byte array to hex encode
     * @return Hex encoded String of the input byte array
     */
    private static String byteArray2Hex(final byte[] hash) {
        Formatter formatter = new Formatter();
        for (byte b : hash) {
            formatter.format("%02x", b);
        }
        return formatter.toString();
    }
}

Related

  1. append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision)
  2. asFormattedStr(String format, String eol, Object... objects)
  3. assertion(final boolean test, final String fmt, final Object... params)
  4. byte2Mac(final byte[] m)
  5. byteArray2Hex(byte[] hash)
  6. byteArray2HexString(byte[] buf)
  7. byteArrayToHex(final byte[] hash)
  8. byteArrayToHexString(byte[] bytes)
  9. byteArrayToHexString(byte[] bytes, int pos, int len)