Code:
#include <stdio.h>
int main()
{
unsigned char aByte = 1; // == 00000001
unsigned char myInput = 126; // just some random value which fits inside a byte (unsigned char)
unsigned char myMask = 170; // 10101010
int cntr = 0;
// after each loop the bit of aByte is shifted 1 position to the left. From the start, which is position 0
// after (!) 7 times shifted to the left, the bit is shifted outside aByte and aByte has value == 0
for(; aByte; aByte <<= 1)
if(aByte & myMask) // test whether the current position of the bit in aByte matches with one of the mask-bits
if(... find out yourself ...) // if so, test whether the current position of aByte also matches with your input
++cntr;
printf("%d matching bits counted\n", cntr);
return(1);
}