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

2019-12-09  本文已影响0人  Matures
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();
    }
上一篇 下一篇

猜你喜欢

热点阅读