int a;
byte buffer[]=byte[4];
JAVA好像不支持这种直接的操作!byte[] 转换成 int
for (int i=0;i<buffer.length;i++)
  a += ((int) buffer[i])*256;int 转换成 byte
int i=0;
while (a>0)
{
   buffer[i++] = a % 256;
   a = a % 256; 
}
              

解决方案 »

  1.   

    你的意思是要进行byte和int之间的转换的话,很简单呀!
    byte有个包装类Byte。里面有个专门转换成int的方法(intValue()),返回的就是int型的值。
    int有个包装类Interger。里面也有个方法(byteValue() ),返回的是byte型的值。
    这样就可以自如的转换了。至于他们的数组间的转换,就是用循环完成就可以了嘛!
      

  2.   

    to noratong:怎么循环啊,int如果数据太大转化成一个byte数据就会丢失了。
      

  3.   

    public static int byteArr2Int(byte[] arrB)
    {
        if (arrB==null || arrB.length!=4) 
        {
         return 0;
        }
        int i = (arrB[0]<<24) + (arrB[1]<<16) + (arrB[2]<<8) + arrB[3];
        return i;
    }public static byte[] int2ByteArr(int i)
    {
        byte[] arrB = new byte[4];
        arrB[0] = (byte)(i>>24);
        arrB[1] = (byte)(i>>16);
        arrB[2] = (byte)(i>>8);
        arrB[3] = (byte)i;
        return arrB;
    }
      

  4.   

    这样做对么
    byte可是有符号的
      

  5.   

    哦,刚才给的那个有问题,换成这个好了,测试通过了的
    public static int[] _MoveX={0xff,0xff00,0x0ff0000,0xff000000};
    public static byte[] uintoBytes(int IntegerSize){    byte Byte4Size[] = new byte[4];    for(int i = 0 ;i<4;i++)    Byte4Size[i] = (byte)((IntegerSize & _MoveX[i]) >> (i*8));    return Byte4Size;}
    public static int byte4toInt(byte[] Byte4Size){   int integer = 0;   for(int i = 0;i<4;i++){ int int_temp = 0; int_temp= int_temp | ((int)Byte4Size[i] & 0xff); integer = integer | (int_temp<<(i*8));  }  return integer;}
      

  6.   

    我倒是有个想法,就是编译通过了,可运行就出现下面的错误:
    Exeception in thread "main" java.lang.NoSuchMethodError:mainint bytes;
    byte signBuffer[]=new byte[4];int to byte[] : signBuffer=((new Integer(bytes)).toString()).getBytes();byte[] to int: bytes=new Integer(new String(signBuffer)).intValue();
      

  7.   

    jokerjava(冷血) :第二次给的那个你测过没? 测一下看看啦,我测试过了,可以用
      

  8.   

    to yishanjushi(伊行) 
    有眉头正确设置
    classpath
      

  9.   

    to jokerjava(冷血) 你那个程序我测试过了,可以用。先谢了。你能不能帮我看看我写的那段用系统类的程序,那个错误怎么处理,不知道classpass还需要设置什么类的路径。