Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Character constant

 
Prathiba krishnamurthy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic