Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# 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).]

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

Mike Curwen
Ranch Hand
Posts: 3695

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?

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,

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.