Java Byte Array to Hex bytesToHex(byte[] raw)

Here you can find the source of bytesToHex(byte[] raw)

Description

Converts bytes to a hex string.

License

Creative Commons License

Parameter

Parameter Description
raw the byte[] to be converted.

Return

the hex representation as a string.

Declaration

public static String bytesToHex(byte[] raw) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from w ww  .  jav a  2  s. c om*/
     * Converts bytes to a hex string.
     *
     * @param raw the byte[] to be converted.
     * @return the hex representation as a string.
     */
    public static String bytesToHex(byte[] raw) {
        if (raw == null) {
            return null;
        }
        final StringBuilder hex = new StringBuilder(2 * raw.length);
        for (final byte b : raw) {
            hex.append(Character.forDigit((b & 0xF0) >> 4, 16)).append(Character.forDigit((b & 0x0F), 16));
        }
        return hex.toString();
    }
}

Related

  1. bytesToHex(byte[] data)
  2. bytesToHex(byte[] data, char[] chars)
  3. bytesToHex(byte[] data, int m, int n)
  4. bytesToHex(byte[] digest)
  5. bytesToHex(byte[] in)
  6. bytesToHex(byte[] raw)
  7. bytesToHex(byte[] raw)
  8. bytesToHex(final byte[] b)
  9. bytesToHex(final byte[] bytes)