File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert from char to byte?

 
D diller
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a heck of a time converting from a char to a byte - probably because chars are two bytes...

In either case, whenever I try to convert I get the ASCII value of the character.

Ex:
if aChar = 4, I get 52 for the value of digit, which is the ASCII value of 4.

Any clues?
 
Paul Clapham
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose you mean that aChar = '4'. Then this is normal, the character is cast to its Unicode representation. Did you want something else to happen? If so, then what?
 
D diller
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wanted digits = 4 like it would if I converted from a String.
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use '4' - '0'. Be careful though to handle the case where your character is not between '0' and '9' inclusive.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a method in the java.lang.Character class called something like numericValue. That might help.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic