Hi I am very new to Java and need a little help
I need to convert a one byte string "x" to an
integer value as in " " = 32 dec
Would anyone know how?

Signature
Charles Albrecht
Charlie's Place BBS - http://cpbbs.synchro.net:8080
telnet://cpbbs.synchro.net.16:8023
Lew - 17 Feb 2008 17:24 GMT
> Hi I am very new to Java and need a little help
> I need to convert a one byte string "x" to an
> integer value as in " " = 32 dec
> Would anyone know how?
Strings in Java are built from the char type, not byte, which unlike the other
integral types is unsigned. You can use chars directly as numbers.
<http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html>
Because int is a wider type than char, you can assign a char to an int with an
implicit widening conversion.
char constants are delimited by single-quotes (apostrophe, or ' ), not
double-quotes.
If you want a single char out of a String you can use the String charAt() method.
<http://java.sun.com/javase/6/docs/api/java/lang/String.html#charAt(int)>
However, a single char might not contain an entire Unicode code point, due to
the use of surrogate pairs. For that you'd use String codePointAt():
<http://java.sun.com/javase/6/docs/api/java/lang/String.html#codePointAt(int)>
If, as in your example, you just want to assign the first (or only) char of
String to an int, you can do something like
int value = " ".charAt(0);

Signature
Lew
Roedy Green - 18 Feb 2008 06:08 GMT
On Sun, 17 Feb 2008 12:00:56 -0500, "Charles Albrecht"
<cwalbrec@sover.net> wrote, quoted or indirectly quoted someone who
said :
>Hi I am very new to Java and need a little help
>I need to convert a one byte string "x" to an
>integer value as in " " = 32 dec
see http://mindprod.com/applet/converter.html
for all you conversion questions.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Charles Albrecht - 18 Feb 2008 06:44 GMT
> On Sun, 17 Feb 2008 12:00:56 -0500, "Charles Albrecht"
> <cwalbrec@sover.net> wrote, quoted or indirectly quoted someone who
[quoted text clipped - 12 lines]
> The Java Glossary
> http://mindprod.com
Thank you both that looks like 2 good answers
I will try them tomorrow night!

Signature
Charles Albrecht
Charlie's Place BBS - http://cpbbs.synchro.net:8080
telnet://cpbbs.synchro.net.16:8023