-->

如何转换特殊字符为十六进制? (Android中)(How to convert special

2019-11-03 07:13发布

将一些特殊字符转换为十六进制值。

例如 :

的“ㅂ”的十六进制值是“E3 85 82”

“ㅈ” 的十六进制值, “ㄷ” 和 “ㄱ” 是 “E3 85 88”, “E3 84 B7”,并且分别为 “E3 84 B1”。

我尝试下面的方法,但它仅适用于“;”,“#”等

Integer.toHexString( “ ㅂ ”),给出了“3142”的值。 但正确的十六进制值应该是“E3 85 82”。

字符串为十六进制

Answer 1:

你的回答编码是UNICODE(十六进制),你需要将其转换为UTF-8(十六进制)

将字符串转换为十六进制。

public static void main(String[] args) throws UnsupportedEncodingException {
    String chr = "ㅂ";
    System.out.print(toHex(chr));
}
//String to hex
public static String toHex(String arg) throws UnsupportedEncodingException {
    //Change encoding according to your need 
    return String.format("%04x", new BigInteger(1, arg.getBytes("UTF8")));
}

输出: - e38582



文章来源: How to convert special characters to hex? ( in Android )