Java Hex Calculate toHexString(byte[] bytes)

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

Description

to Hex String

License

Apache License

Declaration

public static String toHexString(byte[] bytes) 

Method Source Code

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

public class Main {
    private static final int BYTE_MASK = 0xFF;

    public static String toHexString(byte[] bytes) {
        if (bytes != null) {
            StringBuilder hexString = new StringBuilder();

            for (byte b : bytes) {
                String hex = Integer.toHexString(b & BYTE_MASK);
                if (hex.length() == 1) {
                    hexString.append('0');
                }// ww w. ja v  a 2 s. c om
                hexString.append(hex);
            }

            return hexString.toString();
        } else {
            return null;
        }
    }
}

Related

  1. toHexString(byte[] byteArray, boolean withSpaces)
  2. toHexString(byte[] byteArray, int offset, int size)
  3. toHexString(byte[] byteArray, String delim)
  4. toHexString(byte[] byteDigest)
  5. toHexString(byte[] bytes)
  6. toHexString(byte[] bytes)
  7. toHexString(byte[] bytes)
  8. toHexString(byte[] bytes)
  9. toHexString(byte[] bytes)