My code which is simply casting the ascii character to get decimal value and it is working properly. For example:
public static void main(String[] args) {
char character = 'A';
int intChar = (int) character;
System.out.println("Decimal Value is " + intChar);
}
Which returns me correct output as below:
Decimal Value is 65
Above code is working fine when characters range is from 0 to 127 (US-ASCII). But when I am trying to get the decimal value for extended ascii characters it
returns me wrong decimal number. For example
public static void main(String[] args) {
char character = 'Š';
int intChar = (int) character;
System.out.println("Decimal Value is " + intChar);
}
Which returns me incorrect output as below:
Decimal Value is 352
Instead it should return 138 as decimal value. 352 is the Unicode value for character 'Š' but I am expecting 138 which is correct value. Please help me to achieve this.
public static void main(String[] args) {
char character = 'A';
int intChar = (int) character;
System.out.println("Decimal Value is " + intChar);
}
Which returns me correct output as below:
Decimal Value is 65
Above code is working fine when characters range is from 0 to 127 (US-ASCII). But when I am trying to get the decimal value for extended ascii characters it
returns me wrong decimal number. For example
public static void main(String[] args) {
char character = 'Š';
int intChar = (int) character;
System.out.println("Decimal Value is " + intChar);
}
Which returns me incorrect output as below:
Decimal Value is 352
Instead it should return 138 as decimal value. 352 is the Unicode value for character 'Š' but I am expecting 138 which is correct value. Please help me to achieve this.