In Java, Integer.parseUnsignedInt(s) reads the text in s as an unsigned number, so the allowed range is 0 to 4294967295 instead of -2147483648 to 2147483647.
Java has no unsigned int type, so the result is stored in a normal int. Values above 2147483647 use the same 32 bits but print as negative numbers. Use the other unsigned helpers, such as toUnsignedString(), to show them correctly.
A static method of java.lang.Integer (since Java 8): call it on the class, as Integer.parseUnsignedInt(...). Integer lives in java.lang, so no import is needed. parseUnsignedInt() was added in Java 8.
Syntax
Pass the text, and optionally the radix.
Java
int a = Integer.parseUnsignedInt("100"); // 100
int b = Integer.parseUnsignedInt("4294967295"); // -1 (all 32 bits set)
int c = Integer.parseUnsignedInt("ff", 16); // 255
Call
What it does
Integer.parseUnsignedInt(s)
Reads s as an unsigned decimal number.
Integer.parseUnsignedInt(s, radix)
Reads s in the given base.
Integer.toUnsignedString(i)
The reverse: shows an int as an unsigned number.
Long.parseLong(s)
Alternative: parse into a long, which holds the full range without wrapping.
A leading + is allowed, but a leading - is not, even for "-0".
Library declarations
Java
// java.lang.Integer
public static int parseUnsignedInt(String s) throws NumberFormatException
public static int parseUnsignedInt(String s, int radix) throws NumberFormatException
// Java 9 and later also has a CharSequence slice form
Parameters
Parameter
Description
s (String)
The text to read. It must not be null, empty, or start with a minus sign.
radix (int)
The base of the number, from 2 to 36. The one-argument form uses 10.
Return Value
Return Value
Description
int
The 32 bits of the unsigned value. Values above Integer.MAX_VALUE appear negative when printed as a normal int.