Java Integer parseUnsignedInt() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 8+

Definition

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
CallWhat 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

ParameterDescription
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 ValueDescription
intThe 32 bits of the unsigned value. Values above Integer.MAX_VALUE appear negative when printed as a normal int.

Compare with Similar Methods

Compare with the signed and unsigned helpers:

MethodHow it differs
parseInt(s)Signed: rejects anything above 2147483647.
toUnsignedString(i)The matching way to print the result as an unsigned number.
toUnsignedLong(i)Widens the same bits to a positive long.
divideUnsigned(a, b)Divides two values as unsigned numbers.

Java Examples

Example 1 — Parse Numbers Larger Than Integer.MAX_VALUE

Read a few unsigned values and see how the stored int looks when printed normally and as unsigned.

Java
public class IntegerParseUnsignedDemo {
    public static void main(String[] args) {
        String[] texts = {"100", "2147483647", "2147483648", "4294967295"};

        for (String text : texts) {
            int bits = Integer.parseUnsignedInt(text);
            System.out.println(text + " -> int " + bits
                    + ", unsigned " + Integer.toUnsignedString(bits));
        }
    }
}

How It Works

  1. Same bits, two views. Each value is stored in an int. Printed normally it may look negative; toUnsignedString shows the unsigned number.
  2. Up to MAX_VALUE nothing changes. 100 and 2147483647 have the same signed and unsigned text.
  3. Past the signed limit. 2147483648 needs the top bit, so as an int it prints as -2147483648, yet the unsigned text still says 2147483648.
  4. All bits set. 4294967295 is 32 one-bits, which a signed int shows as -1.

Example 2 — Read a Hex Colour and a Network Mask

Use the radix form to read hexadecimal text that fills all 32 bits, such as a colour with an alpha channel.

Java
public class IntegerParseUnsignedHex {
    public static void main(String[] args) {
        int colour = Integer.parseUnsignedInt("ff8800cc", 16);
        System.out.println("colour as int:      " + colour);
        System.out.println("colour as unsigned: " + Integer.toUnsignedString(colour));
        System.out.println("colour as hex:      " + Integer.toHexString(colour));

        int mask = Integer.parseUnsignedInt("ffffff00", 16);
        System.out.println("mask as int:        " + mask);
        System.out.println("mask as unsigned:   " + Integer.toUnsignedString(mask));
    }
}

How It Works

  1. Eight hex digits is 32 bits. "ff8800cc" uses the top bit, so parseInt would reject it, but parseUnsignedInt accepts it.
  2. The int looks negative. The top bit is set, so the stored int prints as -7864116.
  3. Unsigned and hex are friendlier. toUnsignedString gives 4287103180, and toHexString gives back the original digits.
  4. A network mask. "ffffff00" is 255.255.255.0 in dotted form; stored as an int it is -256.

Example 3 — See Which Texts Are Rejected

Compare parseInt and parseUnsignedInt on the same inputs.

Java
public class IntegerParseUnsignedInvalid {
    static String signed(String text) {
        try {
            return String.valueOf(Integer.parseInt(text));
        } catch (NumberFormatException e) {
            return "NumberFormatException";
        }
    }

    static String unsigned(String text) {
        try {
            return String.valueOf(Integer.parseUnsignedInt(text));
        } catch (NumberFormatException e) {
            return "NumberFormatException";
        }
    }

    public static void main(String[] args) {
        String[] inputs = {"3000000000", "-1", "+7", "4294967296"};
        for (String text : inputs) {
            System.out.println(text + ": parseInt=" + signed(text)
                    + ", parseUnsignedInt=" + unsigned(text));
        }
    }
}

How It Works

  1. Two helpers, same inputs. Each helper catches the exception and returns its name, so one line can compare both methods.
  2. Big but legal. 3000000000 is too large for parseInt, but it fits in 32 unsigned bits and comes back as -1294967296.
  3. The minus sign. parseInt accepts -1, but parseUnsignedInt refuses any leading minus.
  4. Plus and overflow. +7 works in both, while 4294967296 is one past the unsigned maximum and fails in both.

Frequently Asked Questions

It reads text as an unsigned 32-bit number (0 to 4294967295) and returns the same 32 bits as a normal int.
Java ints are signed. Any value above 2147483647 sets the top bit, which a signed int shows as a negative number. The bits are still correct.
Call Integer.toUnsignedString(value), or widen it with Integer.toUnsignedLong(value).
No. A leading minus always throws NumberFormatException, even for -0. A leading plus is accepted.
When you just need a number above 2147483647 for calculations. A long holds it directly, with no wrap-around to explain.

Next: remainderUnsigned()

Get the remainder of an unsigned division.

remainderUnsigned() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful