Java 程序以无符号整数的形式获取存储在字节中的值
首先创建带符号字节 −
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
广告