简体   繁体   English

将字节数组转换为十进制

[英]Convert byte array to decimal

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 谢谢

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM