Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ASCII conversion

 
Anders Engstr�m
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! It worked.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that casting a char to an int is unnecessary. You could simply assign the char value to the int.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic