By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,919 Members | 1,625 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,919 IT Pros & Developers. It's quick & easy.

char to ascii integer and back

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
lucas wrote:
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,

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.println((int)'A');
System.out.println((char)65);

Ray
Jul 17 '05 #2

P: n/a
thanx ray,

that did the trick.

lucas

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.