这么搞一下就该看明白了吧
byte[] buffer = {-128,-127,-2,-1,0,1,2,126,127};
int[] databuf = new int[buffer.length];
System.out.println(Byte.MIN_VALUE+"***"+Byte.MAX_VALUE);
for (int i = 0; i < buffer.length; i++)
{
databuf[i] = (int) ((buffer[i] + 256) % 256);
System.out.print(databuf[i]+",");
}
输出结果:
-128***127
128,129,254,255,0,1,2,126,127,
//这不就正好把byte类型转化成正数的int类型了,只不过负值被转化到了128~255之间。
|