Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

# Ascii to Hex

Angela Jessi
Ranch Hand
Posts: 428
How to convert Ascii characters to Hex ?
Thanks
Angela

Mike Curwen
Ranch Hand
Posts: 3695
Something like this? I admit, I had to look in a textbook for that, since the API doesn't really talk about primitive conversions too much. I remember how to do this in C++ with sprintf.

[This message has been edited by Mike Curwen (edited September 20, 2001).]

Adrian Ferreira
Ranch Hand
Posts: 118
Mike,
In fact, you are converting the char ASCII value to Hex not ASCII to hex.

How to convert Ascii characters to Hex ?

Angela, please tell me if I miss understood you.
Dont you want something like this?
System.out.println(0xA); //prints 10
Adrian

Mike Curwen
Ranch Hand
Posts: 3695
Adrian,

While you've got me thinking that I might not have understood Angela's question, I think all you've done is print out a hex literal. That's more like hex to hex, isn't it?

Adrian Ferreira
Ranch Hand
Posts: 118
Mike,
Mike,
Hex "A" means decimal "10".

the hex value of A is: 41

The hex value is 10, not 41.
The hex value for 65 is 41 and 65 is the ASCII representation for 'a'.
41 = 4*16+1 = 65 (ASCII value for 'a')
May be your answer is what Angela is looking for but the question is not clear.
Cheers,
Adrian

Mike Curwen
Ranch Hand
Posts: 3695
Oh sheesh.

I guess my System.out.println should have said "The hex value of the character 'A' is: 41

Honestly, did you think i thought Ah = 41d?

Amazing what a confusion of ideas can result from unclear requirements.