java中的字节数组到十进制转换
我是 Java 新手.我接收字节数组中的 UDP 数据.字节数组的每个元素都有十六进制值.我需要将每个元素转换为整数.
I am new to java. I receive the UDP data in byte array. Each elements of the byte array have the hexadecimal value. I need to convert each element to integer.
如何将其转换为整数?
推荐答案
示例代码:
public int[] bytearray2intarray(byte[] barray)
{
int[] iarray = new int[barray.length];
int i = 0;
for (byte b : barray)
iarray[i++] = b & 0xff;
// "and" with 0xff since bytes are signed in java
return iarray;
}
相关文章