Hey there!
I have a problem with two-dimensional arrays and maybe someone is able to give me a clue about what is going on... What I am trying to achieve here is that I have an array of longs of which every entry has to be stored into a byte array.
This is my code so far:
// just some random numbers
long myValues[4] = {2147483647, 647, 1483, 10};
// this is the two-dimensional array
unsigned char byteArray[4][4];
void setup()
{
Serial.begin(115200);
}
void loop()
{
// just print the values of the array once
for (int i = 0; i < 4; i++)
{
Serial.print(myValues[i]);
Serial.print(" | ");
}
Serial.println();
// run through the rows
for (int i = 0; i < 4; i++)
{
// run through the columns
for (int j = 0; j < 4; j++)
{
byteArray[i][j] = (int)((myValues[j] >> 24) & 0xFF) ;
byteArray[i][j] = (int)((myValues[j] >> 16) & 0xFF) ;
byteArray[i][j] = (int)((myValues[j] >> 8) & 0XFF);
byteArray[i][j] = (int)((myValues[j] & 0XFF));
}
}
// print out the results
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
Serial.print(byteArray[i][j], HEX);
Serial.print(" ");
}
Serial.println();
}
delay(1000);
}
Edit: Okay... I guess what I should be doing is something like
byteArray[i][0] = (int)((myValues[j] >> 24) & 0xFF) ;
byteArray[i][1] = (int)((myValues[j] >> 16) & 0xFF) ;
byteArray[i][2] = (int)((myValues[j] >> 8) & 0XFF);
byteArray[i][3] = (int)((myValues[j] & 0XFF));
but the problem persists. ![]()