Google Groups unterstützt keine neuen Usenet-Beiträge oder ‑Abos mehr. Bisherige Inhalte sind weiterhin sichtbar.

Q: How to convert hexadecimal String to int?

27 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Erik Hietbrink

ungelesen,
14.05.1998, 03:00:0014.05.98
an

Hi

Can anyone tell me how i convert a String filled with a hexadecimal
number to an integer? I'm sure there is a standard function for that
but I cant find it. Help!

Email answer plz to e...@sci.kun.nl

Greetx, Erik


Andrew Ferreira

ungelesen,
14.05.1998, 03:00:0014.05.98
an Erik Hietbrink

You can use Integer.parseInt() like this:

int iDecimalValue = Integer.parseInt( "3E8", 16 );

To go the other way, you can do this:
String hex = Integer.toHexString( 1000 );

'drew

Roedy Green

ungelesen,
14.05.1998, 03:00:0014.05.98
an

Erik Hietbrink asked, wrote, or quoted:

>Can anyone tell me how i convert a String filled with a hexadecimal
>number to an integer? I'm sure there is a standard function for that
>but I cant find it. Help!

For this and the 255 other similar conversion questions, see "conversion"
in the Java glossary. There a table showing you how to convert anything to
anything including your hex String to int.. There is also a program called
the Java Amanuensis that will generate code for you that you can cut/paste.

For the JAVA GLOSSARY and the CMP Utilities: <http://oberon.ark.com/~roedy>
--
Roedy Green Canadian Mind Products

Sponsored by: www.athena.com, makers of Integer, a multiuser
spreadsheet JavaBean. Opinions expressed are not necessarily
those of Athena Design.
-30-

Thomas B. Hoeft

ungelesen,
14.05.1998, 03:00:0014.05.98
an

Standard? ---> Sorry, but you need to convert the hexadecimal to
decimal, base 10, if you want parseInt to work for you (there is no
parseDouble). Other than that, you're on your own.

- good luck

Erik Hietbrink wrote in message <6jeb1h$dfq$1...@studs3.sci.kun.nl>...
>Hi


>
>Can anyone tell me how i convert a String filled with a hexadecimal
>number to an integer? I'm sure there is a standard function for that
>but I cant find it. Help!
>

Rick Miller

ungelesen,
15.05.1998, 03:00:0015.05.98
an

I really wish people wouldn't respond unless they knew what they were
talking about.

Yes, there *IS* a standard way to convert a Hexidecimal string and nothing
in the question had anything to do with the Double class. Sheesh.

Try:

int intValue = Integer.parseInt(hexString, 16);

There are many more functions for such conversions described in the
JDK-1.1.6 online documentation under "java.lang.Integer".

Rick Miller
http://www.execpc.com/~rdmiller/


Thomas B. Hoeft wrote in message <6jfti6$7rp$1...@news.cybernex.net>...

0 neue Nachrichten