让我们首先创建带符号的字节-
byte signedVal = -100;
现在将字节转换为无符号整数-
int unsignedVal = Byte.toUnsignedInt(signedVal);
public class Demo { public static void main(String[] args) { byte signedVal = -100; int unsignedVal = Byte.toUnsignedInt(signedVal); System.out.println("Signed value (byte) = " + signedVal); System.out.println("Unsigned value (byte) = " + unsignedVal); } }
输出结果
Signed value (byte) = -100 Unsigned value (byte) = 156