Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hexadecimal value from String

Status
Not open for further replies.

puntito

Programmer
Mar 22, 2006
18
Hi

My problem is:

I receive a hexadecimal number like a String "ff000001123456"

And I have to say to the program that it is an hexadecimal number.

I´ve tried this:
Code:
intValue = Integer.decode("0x"+gaga);
but i have an error


java.lang.NumberFormatException: For input string: "ff000001123456"


and with this:
Code:
import com.sun.org.apache.xerces.internal.impl.dv.util.HexBin;
... 
HexBin.decode(text)
...
I have compiling problems with the JAR.

So, I need a method to convert that String to an hexadecimal value.

Someone who know how to do it and could help me??? Please !!!
Thanks
 
User the parseInt method of the Integer class:
parseInt(String s, int radix)
Parses the string argument as a signed integer in the radix specified by the second argument.
with a radix of 16:
int s2i = Integer.parseInt(sstring, 16);, where sstring will be the input string.

_________________
Bob Rashkin
 
mmmmm, thank you, but I already use that option too and my problem continue

java.lang.NumberFormatException: For input string: "0xff000001123456"


But thanks for the quick answear!!
 
Knock off the "0x"?

_________________
Bob Rashkin
 
NOP, SAME RESULT

java.lang.NumberFormatException: For input string: "ff000001123456"
 
That number is too large to be an int, use a long

Code:
Long j = Long.decode("0xff000001123456");
System.out.println(j.longValue());

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top