472,353 Members | 972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 162336
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Zach | last post by:
What happens when you compare a char against an integer literal? For example, #include <iostream> using namespace std; int main(int argc, char*...
22
by: hantie | last post by:
In my program, for reducing the complexity, the integer was stored as char, so 2 is stored as '2', which is decimal: 50 Is is possible for me to...
4
by: Rahul | last post by:
Hi, I have following two classes class base{ int i; public: virtual void fun() { cout<<i<<"Base \n"; } }; class d: public base{
10
by: yaniv.dg | last post by:
hi all, i'm bumping into smething very starnge its very simple code but from some reason the program is acting strange this is my code:...
5
by: Melih Onvural | last post by:
Group, I'm trying to get a very basic cast from a string to an integer working. Here is what I'm doing: for i in url: result = int(i)...
1
by: veblen.lee | last post by:
for an example: 'a' value 0x61 '1' value 0x31.
3
by: Firecore | last post by:
Is it possible to convert a char to an int or reverse. eg. int x = 12345 is it pssible to make char y = "12345" without user input?
1
by: jackmejia | last post by:
Hello, I been working on an application that need to build a data package to send it over the network, I have an unsigned short as the data...
3
by: =?utf-8?B?Qm9yaXMgRHXFoWVr?= | last post by:
Hi, I am looking for the best way to convert a string of length 1 (= 1 character as string) to integer that has the same value as numeric...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.