Java.lang.Short 类

java.lang.Short.toUnsignedLong() 方法用于通过无符号转换将参数转换为 long。在无符号到 long 的转换中,long 的高 48 位为零,低 16 位等于 Short 参数的位。因此,零和正短值被映射到数值上相等的长值,负短值被映射到等于输入加 216 的长值。

语法

public static long toUnsignedLong(short x)

参数

x 指定要转换为无符号长整型的值。

返回值

返回通过无符号转换转换为 long 的参数

异常

不适用。

示例:

在下面的示例中,java.lang.Short.toUnsignedLong() 方法用于转换给定的通过无符号转换将短值转换为长值。

import java.lang.*;

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

    //创建短值
    short x = 25;
    short y = -25;

    //打印短值的UnsignedLong值
    System.out.println("UnsignedLong value of x is: " + Short.toUnsignedLong(x)); 
    System.out.println("UnsignedLong value of y is: " + Short.toUnsignedLong(y));  
  }
}

上述代码的输出将是:

UnsignedLong value of x is: 25
UnsignedLong value of y is: 65511