关于java:字符串转16进制ascii

27次阅读

共计 401 个字符,预计需要花费 2 分钟才能阅读完成。

        String a1 = "Hello world";
        byte[] bytes = a1.getBytes();
        for (int i =0; i < bytes.length; i++) {System.out.print(bytes[i]);
            System.out.print("\t");

            String s = Integer.toHexString(bytes[i] & 0xFF);

            System.out.print(s);
            System.out.print("\t");

            byte[] bytes1 = new byte[1];
            bytes1[0] = bytes[i];
            String s1 = new String(bytes1, Charset.defaultCharset());
            System.out.println(s1);

        }

输入后果

72    48    H
101    65    e
108    6c    l
108    6c    l
111    6f    o
32    20     
119    77    w
111    6f    o
114    72    r
108    6c    l
100    64    d

正文完
 0