nBuf = Integer.parseInt(new String(syBuf));
aybuf = Integer.toString(nbuf).getBytes();

解决方案 »

  1.   

    2楼的答案风马牛不相及。
    我要的是类似C中的直接内存操作方式。
    你的答案类似于:
    nBuf=_atoi(ayBuf);
    sprintf("%04d",nBuf,ayBuf);
      

  2.   

    JAVA里面没有相应的函数,自己写一个吧:
    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;
    }
      

  3.   

    1>(int)ayBuf = nBuf.intValue()
    2>如 beming(Aming)所说的一样。
      

  4.   

    java没有指针的这种操作,会引起不安全因素,故此,要自己来写,参照ender(ender) 的方法了。
      

  5.   

    感谢ender。
    还有两点需要注意:
    1,int->bytes[]时,字节顺序要相反。
    2,byte<<24时,要判断byte是否为负,因为java没有unsigned