I'm trying to figure out the best approach to grab data from an array. So heres the deal. I have byte array called curveData[256] filled will hex bytes that I've downloaded from a unit under test. Basically, I am trying to loop through this array of 256 bytes. I want to grab the 1st byte (of a 4 byte chunk), so [0], then [4] [8] and so on…so every 4th byte starting with the first and throwing them into the rpmArray. Then I want to grab the bytes in between, [1][2][3] …etc, and throw them into another array called multOffArray. Here is my code below
|0|1|2|3|4|5|6|7|…………|252|253|254|255|
int i;
byte[] rpmArray = new byte[64];
byte[] multOffArray = new byte[192];
for (i = 0; i < curveData.Length; i++ )
{
if (i%4 == 0 || i%4 == 4)
Array.Copy(curveData, curveData[i], rpmArray, curveData[i], 1);
else
Array.Copy(curveData, curveData[i], multOffArray, curveData[i+1], 3);
}
DisplayData(MessageType.Outgoing, "\n rpmArray: " + rpmArray);
DisplayData(MessageType.Outgoing, "\n multOffArray: " + multOffArray);
I'm getting errors saying that the index is out of bounds. When I check the bytes in the arrays where I’m storing this info, its not in the order that I anticipated and I am missing data. I tried to set it up so that at every index which is a multiple of 4, would initiate copying of data from the source array to my destination array. Maybe somebody can help me get this loop right. It's been a while since I've written code and I know this isn't right. If someone can help it'd be much appreciated.