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

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

Description

bytes To Hex

License

Apache License

Declaration

public static String bytesToHex(byte[] digest) 

Method Source Code

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

public class Main {
    public final static String EMPTY = "";

    public static String bytesToHex(byte[] digest) {
        StringBuffer buffer = new StringBuffer("");
        for (int i = 0; i < digest.length; i++) {
            String hexValue = Integer.toHexString(digest[i] & 0xFF);
            if (hexValue.length() == 1) {
                buffer.append(0);/*from w w w. j  a  va  2  s. c  o m*/
            }
            buffer.append(hexValue);
        }
        return buffer.toString();
    }

    public static String toString(Object obj) {
        if (obj == null) {
            return EMPTY;
        } else {
            return String.valueOf(obj);
        }
    }
}

Related

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