Hexa String to Int java

0

I have:

int number = 0x00000024;

And it have no problems, but now im get it from with de format:

<MAN>
      <NAME hexa="0x00000001"/>
</MAN>

And I try to parse hexa with:

Integer.parseInt(parser.getAttributeValue(0), 16)

But it says:

Unable to parse '0x00000001' as integer

Anyone knows whats happening?

java
hex

2 Answers

6

Remove the 0x:

Integer.parseInt(parser.getAttributeValue(0).substring(2), 16)
answered on Stack Overflow Apr 16, 2012 by MByD
0

Building on the answer in How to convert a hexadecimal string to long in java?, you want:

int num = Long.decode(parser.getAttributeValue(0)).intValue();
answered on Stack Overflow Apr 16, 2012 by trutheality • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0