char to ascii integer and back

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lucas

    char to ascii integer and back

    hello one and all,

    i am very new to java and i need to take an ascii character, say "A" or "a"
    and convert it into its ascii integer code, say 65 or 97 respectively. then
    i need to also go in the reverse from integer 97 to the character "a". what
    is the most efficient way to do this in java.

    lucas


  • Raymond DeCampo

    #2
    Re: char to ascii integer and back

    lucas wrote:[color=blue]
    > hello one and all,
    >
    > i am very new to java and i need to take an ascii character, say "A" or "a"
    > and convert it into its ascii integer code, say 65 or 97 respectively. then
    > i need to also go in the reverse from integer 97 to the character "a". what
    > is the most efficient way to do this in java.[/color]

    Lucas,

    The primitive Java type char represents a 2-byte Unicode character. I
    believe that for ASCII values 0-255 these coincide, but you should check
    with the specification.

    Now you can go back and forth via casting. E.g.

    System.out.prin tln((int)'A');
    System.out.prin tln((char)65);

    Ray

    Comment

    • slukacs

      #3
      Re: char to ascii integer and back

      thanx ray,

      that did the trick.

      lucas

      Comment

      Working...