字节数组转十六进制字符串

public static String bytesToHex(byte[] bytes, int counts) {
        if (bytes == null) {
            return null;
        }
        StringBuffer sbu = new StringBuffer();
        for (int i = 0; i < counts/* bytes.length */; i++) {
            int val = new Byte(bytes[i]).intValue();
            String str = Integer.toHexString(val & 0xff);
            if (str.length() == 1) {
                str = "0" + str;
            }
            sbu.append(str);
            if (i != counts - 1) {
                sbu.append(" ");
            }
        }
        return sbu.toString().toUpperCase();
    }

你可能感兴趣的:(字节数组转十六进制字符串)