6

我有一个表示字符的十六进制值的字符串,例如:“0x6d4b”。我怎样才能得到它表示为字符的字符?

String c = "0x6d4b";
char m = ???
4

4 回答 4

9
// Drop "0x" in order to parse
String c = "6d4b";
// Parse hexadecimal integer
int i = Integer.parseInt( c, 16 );
// Note that this method returns char[]
char[] cs = Character.toChars( i );
// Prints 测
System.out.println( cs );
于 2012-06-27T07:55:53.367 回答
2
String s = "6d4b";
int i = Integer.parseInt( s, 16 );   // to convert hex to integer
char ca= (char) i;
System.out.println(ca);
于 2012-06-27T08:01:58.210 回答
0
System.out.println((char)Integer.parseInt("6d4b",16));
于 2012-06-27T08:05:31.340 回答
-1

尝试这个,

String s ="0x6d4b" ;
        char[] c = s.toCharArray();

        for (char cc : c){

            System.out.print(cc);
        }
于 2012-06-27T07:47:51.127 回答