• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 977
  • Last Modified:

atoi equivalent or different method ??

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
alan_stephens
Asked:
alan_stephens
1 Solution
 
remboCommented:


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
 
alan_stephensAuthor Commented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now