what can i use to convert a character to it's ascii value?

i'm doing some basic encryption exercises as review for my computer science class, and I'm wondering what method I should be using for converting a character to it's specific ascii value?
[197 byte] By [foranta] at [2007-10-3 5:00:58]
# 1

You mean it's numerical value? There might be a method in the Character class, but probably the easiest way is to cast it to an int.

System.out.println('A'); // A

System.out.println((int)'A'); // 65

Note, though, that Java doesn't handle characters in ASCII. It handles them in UTF-8. It so happens that the two overlap for all (or just most?) of ASCII's range, so if you know you're just dealing with ASCII characters anyway, it won't matter. But if your program is taking input from somewhere, you might end up with characters that aren't ASCII. The cast will still work, but you'll get a number > 255.

jverda at 2007-7-14 23:06:33 > top of Java-index,Java Essentials,New To Java...