Solved

atoi equivalent or different method ??

Posted on 1997-10-15
2
961 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

691 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