Java Hex Calculate toHexString(byte[] raw)

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

Description

to Hex String

License

Apache License

Declaration

public static String toHexString(byte[] raw) 

Method Source Code

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

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

    public static String toHexString(byte[] raw) {
        if (raw == null) {
            return null;
        }/*from   w w w.  j  a  v a  2s .  c  om*/
        final StringBuilder hex = new StringBuilder(2 * raw.length);
        for (final byte b : raw) {
            hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F)));
        }
        return hex.toString();
    }

    public static String toHexString(byte b) {
        return new StringBuilder().append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F)))
                .toString();
    }
}

Related

  1. toHexString(byte[] md)
  2. toHexString(byte[] messagePayload)
  3. toHexString(byte[] paramArrayOfByte)
  4. toHexString(byte[] paramArrayOfByte, String paramString, boolean paramBoolean)
  5. toHexString(byte[] raw)
  6. toHexString(byte[] src)
  7. toHexString(byte[] v)
  8. toHexString(byte[] v)
  9. toHexString(byte[] val)