wood burning stoves 2.0*
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Character constant" Watch "Character constant" New topic
Author

Character constant

Prathiba krishnamurthy
Greenhorn

Joined: Feb 18, 2003
Posts: 4
Hi,
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,
Prathiba
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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]
 
It is sorta covered in the JavaRanch Style Guide.
 
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 ???