Hexa String to Int java

Dan*_*ico 0 java hex

我有:

int number = 0x00000024;
Run Code Online (Sandbox Code Playgroud)

它没有问题,但现在我用de格式得到它:

<MAN>
      <NAME hexa="0x00000001"/>
</MAN>
Run Code Online (Sandbox Code Playgroud)

我尝试用以下方法解析hexa:

Integer.parseInt(parser.getAttributeValue(0), 16)
Run Code Online (Sandbox Code Playgroud)

但它说:

Unable to parse '0x00000001' as integer
Run Code Online (Sandbox Code Playgroud)

谁知道发生了什么事?

MBy*_*ByD 6

删除0x:

Integer.parseInt(parser.getAttributeValue(0).substring(2), 16)
Run Code Online (Sandbox Code Playgroud)

  • 实际上,@ DRCB链接中的答案更好Integer.decode:http://docs.oracle.com/javase/6/docs/api/java/lang/Integer.html#decode(java.lang.String) (3认同)