java – Integer. Parseint() does not resolve large negative numbers

When I try integer Why is numberformatexception thrown when parseInt ("80000010", 16)? This is a 32 - bit number, which is the size of Java's int

Editor: the best part is

int z = 0x80000010;
System.err.println("equal to " + z);

According to my calculator print - 2147483632, it is indeed 0x80000010;)

Solution

You can do it

int value = (int) Long.parseLong("80000010",16)

to update:

With Java 8 update (2014), you can write

int value = Integer.parseUnsignedInt("80000010",16);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>