当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Byte toUnsignedLong()用法及代码示例


Java Byte 类的 toUnsignedLong() 方法通过无符号转换将指定的参数转换为 long。

用法:

public static long toUnsignedLong (byte x)

参数:

参数 'x' 表示要转换为 unsigned long 的值。

返回值

此方法返回通过无符号转换从字节转换的long值。

例子1

public class JavaByteToUnsignedLongExample1 {
    public static void main(String[] args) {
        byte b1=-3;
        //converts the specified argument to an long by an unsigned conversion
        Long val=Byte.toUnsignedLong(b1);
        System.out.print("Unsigned long value for "+b1+":"+val);
        System.out.println(val);
    }
}

输出:

Unsigned long value for -3:253253

例子2

public class JavaByteToUnsignedLongExample2 {
    public static void main(String[] args) {
        byte b1=Byte.MIN_VALUE;
        //Converts the argument to an Long by an unsigned conversion
        Long val=Byte.toUnsignedLong(b1);
        //unsigned value for MIN_VALUE
        System.out.print("Unsigned Long value for "+b1+":"+val);
        System.out.println(val);
    }
}

输出:

Unsigned Long value for -128:128128

例子3

public class JavaByteToUnsignedLongExample3 {
    public static void main(String[] args) {
        byte b1=Byte.MAX_VALUE;
        //Converts the argument to an Long by an unsigned conversion
        Long val=Byte.toUnsignedLong(b1);
        //unsigned value for MAX_VALUE
        System.out.print("Unsigned Long value for "+b1+":"+val);
        System.out.println(val);
    }
}

输出:

Unsigned Long value for 127:127127





相关用法


注:本文由纯净天空筛选整理自 Java Byte toUnsignedLong() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。