Solved

atoi equivalent or different method ??

Posted on 1997-10-15
2
950 Views
Last Modified: 2008-03-06
Is there an equivalent to the atoi c function in java ?
JDK1.0.

I have a string(containing a hex number)  which I want to convert to
be an integer.

Alternatively how can I read in a hex number from a
textfield.

If I read it in the following way it will throw an exception
if the number contains a letter (i.e. 6B)

int int_val = new Integer(hexf.getText()).intValue();

So how should I do it ??

Thanks in advance...

Alan

0
Comment
Question by:alan_stephens
2 Comments
 
LVL 4

Accepted Solution

by:
rembo earned 40 total points
ID: 1228718


int int_val = Integer.parseInt(hexf.getText(),16);

also, remember you can't do:

int int_val = new Integer(...) because an int is a
native type and Integer is a class. Just FYI :)

Hope that helps,


0
 

Author Comment

by:alan_stephens
ID: 1228719
Thanks - that worked

In relation to your comment

int int_val = new Integer(...) because an int is a
native type and Integer is a class. Just FYI :)

It will work if you use new Integer(..).intvalue()
which I had above.

Thanks again.
Alan
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now