Java Formatter Usage byteArrayToHex(final byte[] hash)

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

Description

Get the hex string representation of a given byte array

License

Apache License

Parameter

Parameter Description
hash a parameter

Declaration

public static String byteArrayToHex(final byte[] hash) 

Method Source Code

//package com.java2s;
//   Licensed under the Apache License, Version 2.0 (the "License");

import java.util.Formatter;

public class Main {
    /**//from www  . j av  a2 s. com
     * Get the hex string representation of a given byte array
     *
     * @param hash
     * @return
     */
    public static String byteArrayToHex(final byte[] hash) {
        String result;
        Formatter formatter = new Formatter();
        try {
            for (byte b : hash) {
                formatter.format("%02x", b);
            }
            result = formatter.toString();
        } catch (Exception lEx) {
            throw new RuntimeException(lEx);
        }
        return result;
    }
}

Related

  1. assertion(final boolean test, final String fmt, final Object... params)
  2. byte2Mac(final byte[] m)
  3. byteArray2Hex(byte[] hash)
  4. byteArray2Hex(final byte[] hash)
  5. byteArray2HexString(byte[] buf)
  6. byteArrayToHexString(byte[] bytes)
  7. byteArrayToHexString(byte[] bytes, int pos, int len)
  8. bytesToHexString(byte[] bytes)
  9. byteToHex(final byte[] bytes)