关于这俩个方法谁能帮我解释一下具体怎么个使用方法,目前我只知道第一个方法是int转换成byte数组
第二个是byte数组转换成int
目前我的遗憾是第二个方法怎么个使用假如我现在有一套程序
把int 类型的a转换成byte数组
int a=123;
byte[] b=intToBytes4(123);
然后在把byte数组b转换成int类型,但是第二个方法我不知道怎么调用,求助各位大侠帮助-----------------------------------------------------------
//
public static byte[] intToBytes4(int i) {
byte[] mybytes = new byte[4];
mybytes[3] = (byte) (0xff & i);
mybytes[2] = (byte) ((0xff00 & i) >> 8);
mybytes[1] = (byte) ((0xff0000 & i) >> 16);
mybytes[0] = (byte) (int) (((long) 0xff000000 & (long) i) >> 24);
return mybytes;
}
      //第二个参数int nOff如果使用,具体不是很了解
public static int bytes4ToInt(byte mybytes[], int nOff) {
return (0xff & mybytes[nOff + 0]) << 24
| (0xff & mybytes[nOff + 1]) << 16
| (0xff & mybytes[nOff + 2]) << 8 | 0xff & mybytes[nOff + 3];
}

解决方案 »

  1.   

    你是不懂那个nOff吧就是从数组的第几个位置开始转换,Offset。mybytes可以有2个int组成,如果你要提取后面4位(第二个int),
    nOff就是4
      

  2.   

    所以mybytes里可以有很多个int组成,至于你要提取那个数字,就要设置offset了。[byte][byte][byte][byte][byte][byte][byte][byte][byte][byte][byte][byte]
    (          int         )(          int         )(          int         )
    nOff                   nOff                    nOff