我做了以下的尝试,结果不对。
private void byte2int(byte[] byteValue, int intValue)
{
try
{
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pos);
pos.write(byteValue, 0, 4);
DataInputStream dis = new DataInputStream(pis);
intValue = dis.readInt();
}
catch(IOException e)
{
System.out.println("sdfasdfsdafds");
}
}
谁有好的方法呢,共享一下,谢谢。
private void byte2int(byte[] byteValue, int intValue)
{
try
{
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pos);
pos.write(byteValue, 0, 4);
DataInputStream dis = new DataInputStream(pis);
intValue = dis.readInt();
}
catch(IOException e)
{
System.out.println("sdfasdfsdafds");
}
}
谁有好的方法呢,共享一下,谢谢。
Integer.parseInt(byteValue.toString())
return (int) ((((b3 & 0xff) << 24) | ((b2 & 0xff) << 16)
| ((b1 & 0xff) << 8) | ((b0 & 0xff) << 0)));
}
int iIntValue = 0;
for(int i=0;i<4;i++)
{
iIntValue = iIntValue<<8;
iIntValue = iIntValue + (int)oByteArray[i];
}
或者
System.out.println(oByteArray[3] + oByteArray[2]* 256 + oByteArray[1]*256*256 + oByteArray[0]*256*256*256);
^_^
public int decodeInt(byte[] temp)
{
int result = 0; for (int i = 0; i < temp.length; ++i) //取数据
{
result = (int) (((byte)result) << 8);
result += (int) (temp[ i ] & 0x000000ff);
} return result;
}
s = String(byteValue)会使byteValue的数组值变为\u0xx,并不是数字字符,
而parseInt(String)是把"0~9"变为int的,所以会有异常
{
System.out.println(String.valueOf((int)byteValue));
}
谢谢 yonghar(ohno) 我采用了你的方法
谢谢 xhhsld(bluepluto) 你的方法也对