Solved

atoi equivalent or different method ??

Posted on 1997-10-15
2
952 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

863 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

27 Experts available now in Live!

Get 1:1 Help Now