File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes ASCII conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ASCII conversion" Watch "ASCII conversion" New topic

ASCII conversion

Anders Engstr�m

Joined: Jul 25, 2004
Posts: 4
I would like to know if there is any method in Java where I can have an ASCII value (int) as input and get the corresponding char value as output. I would also like to know how it can be done the other way, char as input and its ASCII value (int) as output.
Eric Zanders

Joined: Sep 15, 2004
Posts: 16

To convert an ASCII(int) to its corresponding char:

where i is an int with a value between 33 & 126 (resulting in an upper- or lowercase letter or a number)

The other way 'round:

where a is a char, being upper- or lowercase or a number.

Hoping to have been of any assistance.
Anders Engstr�m

Joined: Jul 25, 2004
Posts: 4
Thanks! It worked.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Note that casting a char to an int is unnecessary. You could simply assign the char value to the int.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: ASCII conversion
jQuery in Action, 3rd edition