Java Byte Array to Hex String bytesToHexString(byte[] bytes)

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

Description

bytes To Hex String

License

Open Source License

Declaration

public static String bytesToHexString(byte[] bytes) 

Method Source Code

//package com.java2s;

public class Main {
    /**//w  w w  .  j  ava  2  s.  c  om
     *  Calculate the SHA1 id of the given string.
     */
    private static final int HEX_RADIX = 16;
    private static final int BITS_PER_NIBBLE = 4;

    public static String bytesToHexString(byte[] bytes) {
        if (bytes == null) {
            return null;
        }

        StringBuffer result = new StringBuffer(bytes.length * 2);

        for (int i = 0; i < bytes.length; i++) {
            result.append(Character.forDigit(
                    (bytes[i] & 0xF0) >> BITS_PER_NIBBLE, HEX_RADIX));
            result.append(Character.forDigit(bytes[i] & 0x0F, HEX_RADIX));
        }

        return result.toString();
    }
}

Related

  1. bytesToHexString(byte[] bytes)
  2. bytesToHexString(byte[] bytes)
  3. bytesToHexString(byte[] bytes)
  4. bytesToHexString(byte[] bytes)
  5. bytesToHexString(byte[] bytes)
  6. bytesToHexString(byte[] bytes)
  7. bytesToHexString(byte[] bytes)
  8. bytesToHexString(byte[] bytes)
  9. bytesToHexString(byte[] bytes)