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
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.
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..
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.
public int[] bytearray2intarray(byte[] barray)
{
int[] iarray = new int[barray.length];
int i = 0;
for (byte b : barray)
iarray[i++] = b & 0xff;
return iarray;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With