Java Byte Array to Hex ByteToHex(byte[] bytes)

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

Description

Byte To Hex

License

Apache License

Declaration

public static String ByteToHex(byte[] bytes) 

Method Source Code

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

public class Main {
    public static String ByteToHex(byte[] bytes) {
        StringBuffer sha1StrBuff = new StringBuffer();

        for (int i = 0; i < bytes.length; ++i) {
            if (Integer.toHexString(255 & bytes[i]).length() == 1) {
                sha1StrBuff.append("0").append(Integer.toHexString(255 & bytes[i]));
            } else {
                sha1StrBuff.append(Integer.toHexString(255 & bytes[i]));
            }//from   w  w  w  . j a va 2s.co m
        }

        return sha1StrBuff.toString();
    }
}

Related

  1. byteToHex(byte[] array, String separator)
  2. byteToHex(byte[] b, int size)
  3. byteToHex(byte[] base)
  4. byteToHex(byte[] buf)
  5. byteToHex(byte[] buffer)
  6. byteToHex(byte[] content, int nLength)
  7. byteToHex(byte[] raw)
  8. byteToHex(final byte b)
  9. byteToHex(final byte b)