Every time i come across the value “-15” i want to put it in a new byte array… how would i do this? I think i’m just tired and getting way to confused and worked up… please help… code is as follows:
fileContent = "S107184CB78120EA52S107184CB78120EA57";
int len = fileContent.length();
byte[] data = new byte[len/2];
for (int i = 0; i < len; i += 2)
{
data[i / 2] = (byte) ((Character.digit(fileContent.charAt(i), 16) << 4) + Character.digit(fileContent.charAt(i+1), 16));
}
this will give me the following: [-15, 7, 24, 76, -73, -127, 32, -22, 82, -15, 7, 24, 76, -73, -127, 32, -22, 87]
what i want from here is to have every element from -15 up until the next -15 (but not including it) in a separate byte array. i want to do that every time i come across another -15.. how would i do this?
Assuming
-15‘s occur randomly, you need a dynamic array, which in java is aList.Once you’ve collected up all your elements, you can convert the List to an array easily enough.
It would look something like this:
Note that this creates a
List<Byte[]>, not aList<byte[]>. I chose this because I could use the.toArray()method ofList. If you want aList<byte[]>, you’ll need to manually literate overdatain the if block.