Java Hex Calculate toHexString(final byte[] bytes)

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

Description

Builds a Hex-String from a byte array.

License

Open Source License

Parameter

Parameter Description
bytes an array containing bytes

Return

a Hex-String of the contents of the supplied byte array.

Declaration

public static String toHexString(final byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static final String HEXES = "0123456789ABCDEF";

    /**//from  w w w .j a  v  a 2 s. co m
     * Builds a Hex-String from a byte array.
     * @param bytes an array containing bytes
     * @return a Hex-String of the contents of the supplied byte array.
     */
    public static String toHexString(final byte[] bytes) {
        final StringBuilder sb = new StringBuilder();
        for (final byte b : bytes) {
            sb.append(HEXES.charAt((b & 0xF0) >> 4));
            sb.append(HEXES.charAt(b & 0x0F));
        }
        return sb.toString();
    }
}

Related

  1. toHexString(final byte[] buffer)
  2. toHexString(final byte[] bytes)
  3. toHexString(final byte[] bytes)
  4. toHexString(final byte[] bytes)
  5. toHexString(final byte[] bytes)
  6. toHexString(final byte[] data)
  7. toHexString(final byte[] data)
  8. toHexString(final byte[] data)
  9. toHexString(final byte[] fieldData)