Hmmm. Just for fun, here's a slightly different approach:
int FindBit(BYTE *firstByte,int numBytes)
{
int result = -1;
// find index of first non-zero byte
int index = 0;
while ((index < numBytes) &&
(firstByte[index] == 0)) {
index++;
}
// find index of bit in non-zero byte
if (index < numBytes) {
result = index * 8;
BYTE mask = 0x01;
while ((firstByte[index] & mask) == 0) {
mask <<= 1;
result++;
}
}
return result;
}
My version of FindBit returns -1 in case there are no 1 bits. Also note that I'm assuming 'Intel' byte/bit ordering.
Software Zen: delete this;