當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。