Solved

atoi equivalent or different method ??

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Timer (static) 9 44
netstat -ano | find "8000" and taskkill /f /pid 2984 3 57
session migration servlets 2 38
check java version using powershell 13 93
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

810 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