Can someone try and explain me or direct me to sites that do this following part of code:
for (int i = 0; i < 15; i++) {
digitalWrite(s0, (i & 1));
digitalWrite(s1, (i & 2) >> 1);
digitalWrite(s2, (i & 4) >> 2);
digitalWrite(s3, (i & 8) >> 3);
}
I understand the the result of the function is translating integer numbers to thier corresponding bit numbers(?)
I don't understand how is happening..
int pins[] = {s0, s1, s2, s3};
for (int i = 0; i < 15; i++) {
for (int b = 0; b < 4; b++) {
digitalWrite(pins[b], bitRead(i, b) ? LOW : HIGH );
}
}
Technically, the interpretation of non-zero for HIGH, is not part of the API. It's just fortuitous. Also, taking the value of HIGH == 1. There is no guarantee that it will always be like that, it's only extremely likely.
Shoot, I always mix up the "sense" of the ternary op. True comes first.
If someone complains that the previous solution also suffers from an assumption of non-zero==true, no, because it is defined for boolean expressions in the language.