java中的字节数组到十进制转换 [英] byte array to decimal convertion in java

查看:24
本文介绍了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;
 }

这篇关于java中的字节数组到十进制转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆