Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Thanks

like image 874
Wearybands Avatar asked May 27 '13 10:05

Wearybands


People also ask

Can byte be decimal?

A byte is a group of 8 bits. A bit is the most basic unit and can be either 1 or 0. A byte is not just 8 values between 0 and 1, but 256 (28) different combinations (rather permutations) ranging from 00000000 via e.g. 01010101 to 11111111 . Thus, one byte can represent a decimal number between 0(00) and 255.

What is byte array format?

A byte array is simply an area of memory containing a group of contiguous (side by side) bytes, such that it makes sense to talk about them in order: the first byte, the second byte etc..

Can we convert byte array to file in Java?

Convert byte[] array to File using Java In order to convert a byte array to a file, we will be using a method named the getBytes() method of String class. Implementation: Convert a String into a byte array and write it in a file.


1 Answers

 public int[] bytearray2intarray(byte[] barray)
 {
   int[] iarray = new int[barray.length];
   int i = 0;
   for (byte b : barray)
       iarray[i++] = b & 0xff;
   return iarray;
 }
like image 130
stinepike Avatar answered Oct 30 '22 05:10

stinepike