Read array values and save in a variable

int k = 0;
unsigned char zz[5] = {0, 1, 1, 1, 0};

Dear please advise to

read above zz array and save the array values in "k" variable. Finally variable value should be

k = 01110; // same as values order in above zz array
Please help
Thanks in advanced

Read in loop with summation and shift

1 Like
(unsigned char a = 0; a < 5; a++) {
    //z += xx[0] ^ yy[0];
    k = zz[a];
    k++;
    k << k;
    Serial.println(k);
  }

This is not succeed please advise

Hi Thanks
Can you please give me a sample code or any reference

Thanks in advanced

int k = 0;
unsigned char zz[5] = {0, 1, 1, 1, 0};

void setup() {
  Serial.begin(115200);
  delay(3000);
  Serial.println();
  Serial.println();
  for (int i = 0; i < 5; ++i) {
    k += zz[i];
    if (i < 4) k = k << 1;
    Serial.println(k, BIN);
    delay(500);
  }
}

void loop() {

1 Like

Start from second array element and get rid the if from the loop :slight_smile:

k = zz[0];
for (int i = 1; i < 5; ++i)  k = k<<1 + zz[i];

I wanted him to come to this himself)))

I doubt that this solution is what he expected :slight_smile:

Is it essential that the value is expressed in octal?

and in the place of the teacher would complicate life a little

unsigned char zz[5] = {'0', '1', '1', '1', '0'};

PS f he wins, then the lesson is understood)))

Wow..... this is working
If I tried my self ????/
Grate help

mark the post where the problem is solved, + to my karma

ua6em Your code is solved my problem
Grate thanks

It seems you don't understand - please add "Solution" mark to the most useful post in the thread.

I really appreciate everyone who replied to my post

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.