How to print the extended ASCII code in java from integer value

后端 未结 4 2045
遇见更好的自我
遇见更好的自我 2021-02-19 13:53
public static void main(String[] args) 
{
int i=153;
int j=63;
System.out.println((char)i);
System.out.println((char)j);
}


OUTPUT:-
?
?

I have some i

4条回答
  •  眼角桃花
    2021-02-19 14:18

    "Extended ASCII" is nebulous. There are many extensions to ASCII that define glyphs for the byte values between 127 and 255. These are referred to as code pages. Some of the more common ones include:

    • CP437, the standard on original IBM PCs
    • ISO 8859-1 also known as Code page 1252, the encoding used for most Western European-language versions of Windows for everything but the console

    You really need to know what character encoding your terminal is expecting, otherwise you'll end up printing garbage. In Java, you should be able to check the value of Charset.defaultCharset() (Charset documentation).

    There are many more ways to encode characters than just single-byte "extended ASCII" code pages. Unicode requires far more code points than 255, so there are various fixed-width and variable-width encodings that are used frequently. This page seems to be a good guide to character encoding in Java.

提交回复
热议问题