java 将字节数组转换为十进制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16770742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 23:58:24  来源:igfitidea点击:

Convert byte array to decimal

javabytearraydecimalhex

提问by Wearybands

I have a byte array and I want to do some manipulation on the basis of the data I have in this array. The content of the byte array is in hexadecimal format.

我有一个字节数组,我想根据这个数组中的数据进行一些操作。字节数组的内容为十六进制格式。

byte[] signal = message.getFieldValue( "_Decoder Message" ).data();

This gives me the byte array with the following content

这给了我包含以下内容的字节数组

[ff ff 11 ff ff 82 05 00 13 00 d7 00 fc dc 03 04 00 00 01 00 00 00 1e 00 00 00 52 00 00]

Is it possible to convert this byte array to an array which contains values in decimal ? Or if I am interested in any specific index how can I convert the value of that index to decimal ?

是否可以将此字节数组转换为包含十进制值的数组?或者,如果我对任何特定索引感兴趣,我该如何将该索引的值转换为十进制?

Let say I want to convert index 18 which in byte array is 01. I am using Java btw.

假设我想转换字节数组中的索引 18 为 01。顺便说一句,我正在使用 Java。

Thanks

谢谢

回答by stinepike

 public int[] bytearray2intarray(byte[] barray)
 {
   int[] iarray = new int[barray.length];
   int i = 0;
   for (byte b : barray)
       iarray[i++] = b & 0xff;
   return iarray;
 }