A
A
Artem Melnykov2021-05-08 18:07:39
Arduino
Artem Melnykov, 2021-05-08 18:07:39

Changing array in Arduino?

Hello, I have an array

data[8] = {0x1B, 0xBE, 0x7D, 0x7D, 0xE0, 0x0, 0x0, 0x0};
, how can I convert it to data[4] = {0xBB, 0xE7, 0xD7, 0xDE};?

PS Maybe for someone this question may seem easy, but I'm stupid very much

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2021-05-08
@NickProgramm

The size cannot be reduced because you declared the array statically.
Rewriting data is not a problem.

data[0] = 0xBB;
data[1] = 0xE7;
data[2] = 0xD7;
data[3] = 0xDE;

P
Prizm, 2021-05-08
@PrizmMARgh

The Arduino C++ language is similar, so you can probably use pointers in it like arrays.
You can use a pointer instead of a regular array, then just
int* data = new int[8]{1,2,3...8};
delete[]data;
data = new int[4]{1,2,3,4};
Perhaps it will not have new and delete operators, as in c ++, but there may be malloc and free methods, as in c.
If there are none, then, most likely, you just need to get by with an array of a fixed size and simply, if necessary, not allow the use of the "cropped" part of the array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question