1个回答
2016-12-20 · 企业短信服务平台。
关注
展开全部
public static void main(String[] args) {
try {
String s1 = new String("张三");
byte b[] = s1.getBytes("UTF-8");
System.out.print(Main.byte2hex(b));
System.out.println(s1);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static String byte2hex(byte[] b) { // 一个字节的数,
// 转成16进制字符串
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++) {
// 整数转成十六进制表示
stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
hs=hs+" ";
}
return hs.toUpperCase(); // 转成大写
}
try {
String s1 = new String("张三");
byte b[] = s1.getBytes("UTF-8");
System.out.print(Main.byte2hex(b));
System.out.println(s1);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static String byte2hex(byte[] b) { // 一个字节的数,
// 转成16进制字符串
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++) {
// 整数转成十六进制表示
stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
hs=hs+" ";
}
return hs.toUpperCase(); // 转成大写
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询