Unicode Error in Java?
public class test {
public static v开发者_如何学Coid main(String[] args) {
char c = 'Q';
int j = c;
System.out.println(j + " " + c);
}
}
The above code outputs 81 Q, but I thought Q is 51 in Unicode? what's happening?!
51 is hexadecimal for 81 (5*16 + 1 = 81). Q is 81 in decimal, 0x51 in hex, U+0051 in Unicode, which are all the same thing.
See for example the entry for Q on this page.
'Q' is 81 decimal value, 51 hexadecimal value. Applies to ASCII, ISO 8859-1 (Latin 1) and in UTF-8.
精彩评论