日期:2014-05-20 浏览次数:20779 次
public static void main(String args[]) { byte[] bt = new byte[3]; bt[0] = 0x66; bt[1] = 0x65; bt[2] = 0x61; System.out.println(Integer.parseInt(new String(bt), 16)); }
------解决方案--------------------
public static int bytesToInt(byte[] ba) {
if (ba.length <= 0 || ba.length > 4) {
throw new RuntimeException();
}
int result = 0;
int temp = 0;
for (int i = ba.length - 1; i >= 0; i--) {
temp = ba[i] & 0xFF;
result = result * 0x100 + temp;
}
return result;
}
------解决方案--------------------