PA3040
March 11, 2023, 7:00am
1
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
ua6em
March 11, 2023, 7:05am
2
Read in loop with summation and shift
1 Like
PA3040
March 11, 2023, 7:10am
3
ua6em:
summation and shift
(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
ua6em
March 11, 2023, 7:42am
4
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
b707
March 11, 2023, 7:53am
5
Start from second array element and get rid the if from the loop
k = zz[0];
for (int i = 1; i < 5; ++i) k = k<<1 + zz[i];
ua6em
March 11, 2023, 7:54am
6
I wanted him to come to this himself)))
b707
March 11, 2023, 7:56am
7
I doubt that this solution is what he expected
Is it essential that the value is expressed in octal?
ua6em
March 11, 2023, 8:01am
9
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)))
PA3040
March 11, 2023, 8:28am
10
Wow..... this is working
If I tried my self ????/
Grate help
ua6em
March 11, 2023, 8:38am
11
mark the post where the problem is solved, + to my karma
PA3040
March 11, 2023, 8:45am
12
ua6em Your code is solved my problem
Grate thanks
b707
March 11, 2023, 9:09am
13
It seems you don't understand - please add "Solution" mark to the most useful post in the thread.
PA3040
March 11, 2023, 9:21am
14
I really appreciate everyone who replied to my post
1 Like
system
Closed
September 7, 2023, 9:21am
15
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.