字符串转16进制、ascii

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); }

【字符串转16进制、ascii】输出结果
7248H 10165e 1086cl 1086cl 1116fo 3220 11977w 1116fo 11472r 1086cl 10064d

    推荐阅读