开发者

Unicode Error in Java?

开发者 https://www.devze.com 2023-04-04 09:32 出处:网络
public class test { public static v开发者_如何学Coid main(String[] args) { char c = \'Q\'; int j = c;
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号