Java Hex Calculate toHex(byte[] bytes)

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

Description

to Hex

License

Apache License

Declaration

public static String toHex(byte[] bytes) 

Method Source Code

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

public class Main {

    public static String toHex(byte[] bytes) {
        if (bytes != null && bytes.length > 0) {
            StringBuilder buff = new StringBuilder(bytes.length << 1);
            String tmp = null;/*  ww w.ja  v a2  s .com*/
            for (int i = 0; i < bytes.length; i++) {
                tmp = (Integer.toHexString(bytes[i] & 0xFF));
                if (tmp.length() == 1) {
                    buff.append('0');
                }
                buff.append(tmp);
            }
            return buff.toString();
        }

        return null;
    }
}

Related

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