简体   繁体   中英

About return value of Integer.toString(char)

如果Integer.toString(c)返回1087 ,则char变量c的可能值是多少?

When you call Integer.toString() with a char :

char c = ...
Integer.toString(c);

the char (16 bit) will be converted to an int (32 bit) by adding leading zeros.

That means if the output is 1087, then the original char's binary is 10000111111 (in hex 0x043F). It should be п accoding to this table .

public static void main(String[] args) {
    char c = 'п';
    System.out.println(Integer.toString(c)); // 1087
}

您可以执行Character.toString(c)而不是Integer.toString(c)并获取字符表示形式,而不是整数表示形式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM