extended ASCII Conversion in Java

Joined
Jan 2, 2013
Messages
2
Reaction score
0
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top