Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Convert from char to byte?
D diller
Greenhorn
Posts: 29
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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:
byte digit = (byte) aChar;
if aChar = 4, I get 52 for the value of digit, which is the ASCII value of 4.
Any clues?
Paul Clapham
Marshal
Posts: 28193
95
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Wanted digits = 4 like it would if I converted from a
String
.
Rob Spoor
Sheriff
Posts: 22783
131
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Use '4' - '0'. Be careful though to handle the case where your character is not between '0' and '9' inclusive.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
Campbell Ritchie
Marshal
Posts: 79177
377
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
There is a method in the
java.lang.Character
class called something like numericValue. That might help.
I think I'll just lie down here for a second. And ponder this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How can I do this?
How to print ASCII values of all characters?
ASCII TO EBCDIC conversion preserving COMP-3
Packed decimal conversion - Java
convert character to ascii and back
More...