Hum... I am missing something or you just want to cast a char to a byte/int
in Java?

char x = 'B';  // or "Bravo".charAt(0) if you start with a string
byte y = (byte) x;
System.out.println("y=" + y); // should give you 66

and vice-versa:
char z = (char) y;
System.out.println("z=" + z); // should give you B

The only thing you need to watch is the byte number, I think you get a
number between -128 and +127, so you may need to adjuct depending on your
needs.

BTW I've not tested the code above, I'm just typing it as I speak.

HTH
Nic

On 19/03/06, David Kerber <[EMAIL PROTECTED]> wrote:
>
> I know "Ascii value" isn't quite the correct term, but it's the only one
> I could come up with.
>
> What Im trying to come up with is the simplest way of coming up with the
> numeric value associated with a given character, and to go back the
> other direction as well.  In VB, these are the ASC() and chr()
> functions.  I know how to get these values by going through a Byte type,
> but is there a quicker way to get (for example):
>
> Starting with "B", return 66, or starting with " " (one space), return 32?
> Going the other way, 66 should return "B", and 32 should return " ".
>
> Thanks for any suggestions!
> DAve
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to