Java Integer divideUnsigned() Method

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

Definition

In Java, Integer.divideUnsigned(dividend, divisor) divides two int values while treating their 32 bits as unsigned numbers. The quotient is returned in an int.

The normal / operator is signed, so it gives a different answer whenever a value has its top bit set (a negative int). For example, -1 divided by 2 is 0 with /, but as an unsigned value 4294967295 divided by 2 is 2147483647.

A static method of java.lang.Integer (since Java 8): call it on the class, as Integer.divideUnsigned(...). Integer lives in java.lang, so no import is needed. divideUnsigned() was added in Java 8.

Syntax

Pass the dividend first, then the divisor.

Java
int a = Integer.divideUnsigned(100, 7);   // 14
int b = Integer.divideUnsigned(-1, 2);    // 2147483647 (4294967295 / 2)
int c = -1 / 2;                           // 0 (signed division)
CallWhat it does
Integer.divideUnsigned(a, b)Unsigned quotient of a divided by b.
Integer.remainderUnsigned(a, b)The unsigned remainder that goes with it.
a / bNormal signed division.
Integer.toUnsignedLong(a) / Integer.toUnsignedLong(b)The same answer, using long arithmetic.

Both arguments are read as unsigned. The result is stored in an int, so a large quotient may print as a negative number; use toUnsignedString() to show it.

Library declarations
Java
// java.lang.Integer
public static int divideUnsigned(int dividend, int divisor)

Parameters

ParameterDescription
dividend (int)The number to divide, read as unsigned.
divisor (int)The number to divide by, read as unsigned. It must not be 0.

Return Value

Return ValueDescription
intThe unsigned quotient, rounded down. Print it with toUnsignedString() if it may be above Integer.MAX_VALUE.

Compare with Similar Methods

Related methods:

MethodHow it differs
remainderUnsigned(a, b)The unsigned remainder after the same division.
compareUnsigned(a, b)Unsigned comparison of two values.
toUnsignedLong(i)Widens an unsigned value to a long.
parseUnsignedInt(s)Reads an unsigned value from text.

Java Examples

Example 1 — Divide Large Values Both Ways

Divide the same pairs with the / operator and with divideUnsigned.

Java
public class IntegerDivideUnsignedDemo {
    public static void main(String[] args) {
        int[][] pairs = {{100, 7}, {-1, 2}, {-1, 10}, {Integer.MIN_VALUE, 2}};
        for (int[] pair : pairs) {
            System.out.println(pair[0] + " / " + pair[1]
                    + ": signed " + (pair[0] / pair[1])
                    + ", unsigned " + Integer.divideUnsigned(pair[0], pair[1]));
        }
    }
}

How It Works

  1. Positive numbers agree. 100 divided by 7 is 14 with both, because nothing has the top bit set.
  2. -1 is huge when unsigned. It reads as 4294967295, so dividing by 2 gives 2147483647 instead of 0.
  3. Another divisor. 4294967295 divided by 10 is 429496729, while signed division says -1 / 10 is 0.
  4. MIN_VALUE. Read as 2147483648, half of it is 1073741824, which has the opposite sign from the signed answer.

Example 2 — Split a Large Unsigned Total Between Workers

Read a total above Integer.MAX_VALUE, divide it among 8 workers, and print each result in unsigned form.

Java
public class IntegerDivideUnsignedShare {
    public static void main(String[] args) {
        int total = Integer.parseUnsignedInt("4000000000");
        int workers = 8;

        int share = Integer.divideUnsigned(total, workers);
        int left = Integer.remainderUnsigned(total, workers);

        System.out.println("total as int:    " + total);
        System.out.println("total unsigned:  " + Integer.toUnsignedString(total));
        System.out.println("share each:      " + Integer.toUnsignedString(share));
        System.out.println("left over:       " + left);
        System.out.println("signed share:    " + (total / workers));
    }
}

How It Works

  1. A value too big for a signed int. 4000000000 is above 2147483647, so parseUnsignedInt stores it as the negative int -294967296.
  2. Unsigned division. Dividing 4000000000 by 8 gives exactly 500000000, with nothing left over.
  3. The signed division is wrong. The / operator divides -294967296 by 8 and returns -36870912.
  4. Print with the unsigned helper. toUnsignedString shows the real numbers; the variables themselves just hold bits.

Example 3 — See Division by Zero and Very Large Divisors

Try a zero divisor, a divisor with the top bit set, and equal numbers.

Java
public class IntegerDivideUnsignedEdge {
    public static void main(String[] args) {
        System.out.println("5 / -1 (unsigned):  " + Integer.divideUnsigned(5, -1));
        System.out.println("-1 / -1 (unsigned): " + Integer.divideUnsigned(-1, -1));
        System.out.println("-2 / -1 (unsigned): " + Integer.divideUnsigned(-2, -1));

        try {
            Integer.divideUnsigned(10, 0);
        } catch (ArithmeticException e) {
            System.out.println("divide by zero -> ArithmeticException");
        }
    }
}

How It Works

  1. A negative divisor is huge. As unsigned, -1 is 4294967295, and 5 divided by that is less than 1, so the result is 0.
  2. Same number twice. -1 divided by -1 is 1, as for any number divided by itself.
  3. Just below the divisor. -2 is 4294967294, which is smaller than the divisor, so the quotient is 0.
  4. Zero still fails. A divisor of 0 throws ArithmeticException, even though unsigned numbers cannot be negative.

Frequently Asked Questions

It divides two ints as unsigned 32-bit numbers and returns the quotient as an int.
The / operator is signed. When a number is negative as an int, / uses the negative value, while divideUnsigned uses the large unsigned value with the same bits.
Yes. A divisor of 0 throws ArithmeticException.
The quotient is stored in a signed int. If it is above 2147483647, the top bit is set. Print it with Integer.toUnsignedString.
Call Integer.remainderUnsigned(a, b) with the same arguments.

Next: doubleValue()

Convert an Integer to a primitive double.

doubleValue() 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.

13 people found this page helpful