首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

byte int 变换

2012-12-27 
byte int 转换/** * 将byte类型数据转为int型 */public static int bytesToInt(byte[] bytes) {int mask

byte int 转换

/** * 将byte类型数据转为int型 */public static int bytesToInt(byte[] bytes) {  int mask = 0xff, temp = 0, result = 0;  for (int i = 0; i < 4; i++) {   result <<= 8;   temp = bytes[i] & mask;   result |= temp;  }  return result;}/** * 将int类型数据转为byte型 */public static byte[] intToBytes(int num){  byte[] result = new byte[4];  for(int i=0;i<4;i++){   result[i] = (byte)(num>>>(24-i*8));  }  return result;}

热点排行