Hi
Is there a more compact method of expressing this statement below, I'm using it to shift the bits 1 position to the left ? bitIndex = bitIndex <<1;
// sample of code to reading data from a MT8870 DTMF ic
const byte pins[] = {11,10,9,8};
byte bitIndex = 1;
byte val = 0;
byte data = 0;
//read the 4 data pins from MT8870
for (byte i=0; i<4; i++)
{
val = digitalRead(pins[i]);
if (val)
data |= bitIndex;
bitIndex = bitIndex << 1; //shift bits left
}
Didn't think of that one I just happen to pick those pins.
Is there a problem solving in c book anyone can recommend to me so I
Can get more experience solving these type of problems. I feel like Im doing things the hard way kinda step by step. It's very interesting how different people code the same task.
A minor sidenote: My experince is that the compiler is not all that stupid - it usually does not matter how "compact" you write the code, it ends up with the same generated code. So unless one is having a timecritical code, write things the obvious human friendly way. (Reading tones from DTMF signal is probably not going to break if the loop takes 10us or 20us to do)