Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By hardwired

Thread: How to obtain ASCII code of a character

  1. #1
    karma is offline Member
    Join Date
    May 2007
    Posts
    6
    Rep Power
    0

    Default How to obtain ASCII code of a character

    I want to convert a character to its ASCII code. How can i do this?

  2. #2
    levent Guest

    Default

    You can cast your character into an int simply:

    Java Code:
         int ascii_z = (int) 'z';

  3. #3
    jSarK0Y is offline Member
    Join Date
    Apr 2008
    Posts
    21
    Rep Power
    0

    Default

    karma
    u can do and so: int ascii_code=str.codePointAt(i), but i have another questsion: what func is for reverse task?

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
            char x = 'x';
            int cast = (int)x;
            int codePoint = String.valueOf(x).codePointAt(0);
            char again = (char)codePoint;
            System.out.printf("x = %s  cast = %d  codePoint = %d  again = %s%n",
                               x, cast, codePoint, again);
    Vbabey likes this.

  5. #5
    jSarK0Y is offline Member
    Join Date
    Apr 2008
    Posts
    21
    Rep Power
    0

Similar Threads

  1. Getting ASCII codes of character
    By gapper in forum New To Java
    Replies: 1
    Last Post: 02-02-2008, 09:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •