This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Character constant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Character constant" Watch "Character constant" New topic

Character constant

Prathiba krishnamurthy

Joined: Feb 18, 2003
Posts: 4
In general if I give an input string like "0x0001" and If I extract the single characters then it will be interpreted as a character. Ex: If I extract the 3rd character from the string '0' will be extracted and if I do some arithmetic operations like multiplication then the ascii value of '0' ie. 48 will be mulitiplied with the value with which I am multiplying. Instead I want integer 0 to get multiplied with some other value in this example and not the ascii of '0' ie. 48. How it can be implemented in C? kindly let me know if anybody knows the answer
Thanks & Regards,
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

Are you really asking about C here in the beginner's Java forum?
In 'C', the traditional technique is just to use (c - 48) as the value of a decimal digit, where c is a character known to be in the range 0-9. If the character is a-D or a-d, then you have to check for those and use 10-15.
In Java, you can use the static method Character.getNumericValue() method, which can handle decimal and hexidecimal digits for many international character sets.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Character constant
Similar Threads
How do I read (right to left) from a string one character at a time?
ASCII value for Empty String.
Character Representation Doubt
how to get int value ?
Can someone explain this ???