Java Short - toUnsignedInt() Method
The java.lang.Short.toUnsignedInt() method is used to convert the argument to an int by an unsigned conversion. In an unsigned conversion to an int, the high-order 16 bits of the int are zero and the low-order 16 bits are equal to the bits of the short argument. Consequently, zero and positive short values are mapped to a numerically equal int value and negative short values are mapped to an int value equal to the input plus 216.
Syntax
public static int toUnsignedInt(short x)
Parameters
x |
Specify the value to convert to an unsigned int. |
Return Value
Returns the argument converted to int by an unsigned conversion
Exception
NA.
Example:
In the example below, the java.lang.Short.toUnsignedInt() method is used to convert the given short value to an int by an unsigned conversion.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating short values short x = 25; short y = -25; //printing UnsignedInt value of short values System.out.println("UnsignedInt value of x is: " + Short.toUnsignedInt(x)); System.out.println("UnsignedInt value of y is: " + Short.toUnsignedInt(y)); } }
The output of the above code will be:
UnsignedInt value of x is: 25 UnsignedInt value of y is: 65511
❮ Java.lang - Short