Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2008

Tip: Looking for answers? Try searching our database.

Converting

Thread view: 
Charles Albrecht - 17 Feb 2008 17:00 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?

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.