Whats the best way to extract a bit from an unsigned char .In my opinion ,I think this works perfectly well`
int bit;
unsigned char buffer;
bit= 1 & (buffer>>3) //`if i want to extract the fourth bit
bit= 1 & (buffer>>7)//if i want to extract the 8 bit
If you do not care for the bit to be in the least significant position (e.g. because you need it for a boolean condition) you can do this:
This may be faster because of constant folding: it is only one operation at runtime instead of two.