Java.lang Package Classes

Java Integer - toUnsignedLong() Method



The java.lang.Integer.toUnsignedLong() method is used to convert the argument the argument to a long by an unsigned conversion. In an unsigned conversion to a long, the high-order 32 bits of the long are zero and the low-order 32 bits are equal to the bits of the integer argument. Consequently, zero and positive int values are mapped to a numerically equal long value and negative int values are mapped to a long value equal to the input plus 232.

Syntax

public static long toUnsignedLong(int x)

Parameters

x Specify the value to convert to an unsigned long.

Return Value

Returns the argument converted to long by an unsigned conversion.

Exception

NA.

Example:

In the example below, the java.lang.Integer.toUnsignedLong() method is used to convert the given int value to a long by an unsigned conversion.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {

    //creating int values
    int x = 5;
    int y = -5;

    //creating toUnsignedLong value of int values
    long p = Integer.toUnsignedLong(x);
    long q = Integer.toUnsignedLong(y);

    //printing toUnsignedLong value of int values
    System.out.println("toUnsignedLong value of x is: " + p); 
    System.out.println("toUnsignedLong value of y is: " + q);  
  }
}

The output of the above code will be:

toUnsignedLong value of x is: 5
toUnsignedLong value of y is: 4294967291

❮ Java.lang - Integer