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


Java Byte toUnsignedInt()用法及代碼示例


Java Byte 類的 toUnsignedInt() 方法通過無符號轉換將指定的參數轉換為 int。

用法:

public static int toUnsignedInt (byte x)

參數:

參數 'x' 表示要轉換為無符號整數的值。

返回值

此方法返回通過無符號轉換從字節轉換的 int 值。

例子1

public class JavaByteToUnsignedIntExample1
 {
    public static void main(String[] args) {
        byte b1=-34;
        //Converts the argument to an int by an unsigned conversion
        int val=Byte.toUnsignedInt(b1);
        System.out.print("Unsigned Int value for "+b1+":"+val);
        System.out.println(val);
    }
}

輸出:

Unsigned Int value for -34:222222

例子2

public class JavaByteToUnsignedIntExample2 {
    public static void main(String[] args) {
        byte b1=Byte.MAX_VALUE;
        int val=Byte.toUnsignedInt(b1);
        System.out.print("Unsigned Int value for "+b1+":"+val);
        System.out.println(val);
    }
}

輸出:

Unsigned Int value for 127:127127

例子3

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

輸出:

Unsigned Int value for -128:128128





相關用法


注:本文由純淨天空篩選整理自 Java Byte toUnsignedInt() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。