int id = ((reply[0] & 0x3));
id = (id<<7) | (reply[1] & 0x7F);
Suppose I have a reply array storing 2 byte reply[0] and reply[1].
I wanna read the last two bits in the first byte and all the bits in the second byte, then adding them together
why the code above is going to work, can anyone explain?
Convert to binary and you will get your answer.
binary of 3 is 11. if you use
logical &with 11 you will end up only with the last two bits. That’s the answer to your first part.For the second part, I don’t think it will do what you intended it too. You can use
logical AND(for carry) andlogical XORto add individual bits.Try to figure it out ^_^