This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Servlets and the fly likes Get Ascii value for a Char Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Get Ascii value for a Char" Watch "Get Ascii value for a Char" New topic
Author

Get Ascii value for a Char

Yakubu Lawan
Greenhorn

Joined: Jan 23, 2002
Posts: 7
Please, I can't seem to find any function to get the ascii value of a Character e.g. 'A' is 65...
and also a function to convert decimal to hexadecimal.
Thanks.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
There might be a function but I am not sure. You can just cast your character to an int though, as in...
System.out.println("A is : " + (int)'A');


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12325
    
    1
For characters in the ASCII range 0 - 127, the value in a Unicode char is the same as ASCII. You can cast it to a byte or int.
For a function to format an int as a hexidecimal or other base string, look at the Integer class static methods.
String s = Integer.toHexString( myint )
Bill


Java Resources at www.wbrogden.com
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Moved from Servlets -> Java In General - Beginner
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get Ascii value for a Char
 
Similar Threads
Get Ascii value for a Char
How to get ASCII Value
Get Ascii value for a character
Char To Int a->1 b->2 c->3
Char into Integer