
java如何把byte数组里的十六进制转换成int类型,如下图的数据,杂么转换,跪求方法和代码
3个回答
展开全部
示例
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进制的
展开全部
如果都在内存里,直接隐式类型转
追问
是通过sockert读过来的,不会隐式类型转换吧?
DatagramSocket ds=new DatagramSocket(INTPORT);
byte[] buf = new byte[1024];
DatagramPacket dp = new DatagramPacket(buf, buf.length);
ds.receive(dp);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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');
}
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);
我是这样读过来的数据,这个方法可以吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |