extended ASCII Conversion in Java

Discussion in 'Java' started by gshln, Jan 2, 2013.

  1. gshln

    gshln

    Joined:
    Jan 2, 2013
    Messages:
    2
    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.
    gshln, Jan 2, 2013
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. brrrdog
    Replies:
    0
    Views:
    827
    brrrdog
    Jul 9, 2003
  2. Geoff Warnock
    Replies:
    2
    Views:
    7,987
    Daniel Tryba
    Mar 9, 2005
  3. kristofvdw@matt.es

    Identifying extended ASCII subset

    kristofvdw@matt.es, Nov 7, 2005, in forum: XML
    Replies:
    12
    Views:
    4,115
    Richard Tobin
    Nov 8, 2005
  4. Bob Hartung
    Replies:
    5
    Views:
    8,485
    shan23
    May 28, 2009
  5. James O'Brien
    Replies:
    3
    Views:
    246
    Ben Morrow
    Mar 5, 2004
Loading...

Share This Page