java如何把byte数组里的十六进制转换成int类型,如下图的数据,杂么转换,跪求方法和代码

如题所述

示例

package com.sdvdxl.other;

public class Test {
public static void main(String[] args) {
byte[] bytes = new byte[] {0x00,0x53};
for (byte b : bytes) {
System.out.println(Integer.valueOf(b));
}
}
}

结果:

0

83


PS : 使用的时候会自动转换成10进制的

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-30
如果都在内存里,直接隐式类型转追问

是通过sockert读过来的,不会隐式类型转换吧?
DatagramSocket ds=new DatagramSocket(INTPORT);
byte[] buf = new byte[1024];
DatagramPacket dp = new DatagramPacket(buf, buf.length);
ds.receive(dp);

第2个回答  2013-09-30
public void static void main(String [] args){
byte [] bytes={Ox00,Ox02,Ox03,Ox88.........}; //原数组
int [] ints=new int[bytes.length]; //新数组
for(int i=0;i<bytes.length;i++){
ints[i]=bytes[i]/10*16+bytes[i]%10;
}
System.out.print(ints[i]+'\t');
}追问

DatagramSocket ds=new DatagramSocket(INTPORT);
byte[] buf = new byte[1024];
DatagramPacket dp = new DatagramPacket(buf, buf.length);
ds.receive(dp);
我是这样读过来的数据,这个方法可以吗

相似回答