File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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: 24195

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
It's not a secret anymore!