wood burning stoves 2.0*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ASCII conversion" Watch "ASCII conversion" New topic
Author

ASCII conversion

Anders Engstr�m
Greenhorn

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
Greenhorn

Joined: Sep 15, 2004
Posts: 16
Anders,

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.
Eric
Anders Engstr�m
Greenhorn

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

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]
 
Consider Paul's rocket mass heater.
 
subject: ASCII conversion