Java Short - toUnsignedLong() Method
The java.lang.Short.toUnsignedLong() method is used to convert the argument to a long by an unsigned conversion. In an unsigned conversion to a long, the high-order 48 bits of the long 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 long value and negative short values are mapped to a long value equal to the input plus 216.
Syntax
public static long toUnsignedLong(short 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.Short.toUnsignedLong() method is used to convert the given short value to a long 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 UnsignedLong value of short values System.out.println("UnsignedLong value of x is: " + Short.toUnsignedLong(x)); System.out.println("UnsignedLong value of y is: " + Short.toUnsignedLong(y)); } }
The output of the above code will be:
UnsignedLong value of x is: 25 UnsignedLong value of y is: 65511
❮ Java.lang - Short