Java Byte Array to String bytesToString(final byte[] bytes)

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

Description

Returns a string representation of the supplied byte array in hex format.

License

Open Source License

Parameter

Parameter Description
bytes to create hex string with

Return

hex string

Declaration

public static String bytesToString(final byte[] bytes) 

Method Source Code

//package com.java2s;
/* See LICENSE for licensing and NOTICE for copyright. */

public class Main {
    /**/*from w w  w .  j  a v  a  2s. co m*/
     * Returns a string representation of the supplied byte array in hex format.
     *
     * @param  bytes  to create hex string with
     *
     * @return  hex string
     */
    public static String bytesToString(final byte[] bytes) {
        final StringBuilder sb = new StringBuilder(bytes.length * 2);
        // CheckStyle:MagicNumber OFF
        for (byte b : bytes) {
            final int v = b & 0xff;
            if (v < 16) {
                sb.append('0');
            }
            sb.append(Integer.toHexString(v)).append(":");
        }
        // CheckStyle:MagicNumber ON
        return sb.toString().toUpperCase();
    }
}

Related

  1. bytesToString(byte[] input)
  2. bytesToString(byte[] myByte)
  3. bytesToString(byte[] value)
  4. bytesToString(char[] bytes, boolean le, boolean signed)
  5. bytesToString(final byte[] arr, final boolean signed, final boolean littleEndian, final String sep)
  6. bytesToString(final byte[] data)
  7. bytesToString(int bytes)
  8. bytesToString(int bytes)
  9. bytesToString(int... bytesInt)