469,326 Members | 1,351 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

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
Jul 17 '05 #1
2 162079
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
thanx ray,

that did the trick.

lucas

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Zach | last post: by
22 posts views Thread by hantie | last post: by
4 posts views Thread by Rahul | last post: by
10 posts views Thread by yaniv.dg | last post: by
5 posts views Thread by Melih Onvural | last post: by
1 post views Thread by veblen.lee | last post: by
3 posts views Thread by Firecore | last post: by
3 posts views Thread by =?utf-8?B?Qm9yaXMgRHXFoWVr?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.