`
windywindy
  • 浏览: 167863 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

byte int的转换

阅读更多
public static byte[] int2Byte(int temp){
		byte b[] = new byte[4];
		for (int i = b.length-1; i >= 0; i--) {
			b[i] = new Integer(temp & 0xff).byteValue();
			temp = temp >> 8;
		}
		return b;
	}


public static int byte2Int(byte[] b){
		int temp=0;
		for(int i=0;i<3;i++){
			if(b[i]<0){
				temp+=(b[i]+256);
			}else{
				temp+=b[i];
			}
			temp*=256;
		}
		temp+=b[3];
		if(b[3]<0){
			temp+=256;
		}
		return temp;
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics