473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 162485
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* argv) { signed char c1 = 150; if (c1 < 150)...
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 obtain the integer value of '2' in the program,...
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: #include<stdio.h> #include<conio.h> void main(void) {...
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) counter += 1; return result;
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 length, this is two bytes. On the server side I am...
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 representation of that character. Background: I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.