To check for the proper bit in a bitmap you have to create a function that will contain a valid mask and shift the mask across the bitmap. Using bitwise operations you can easily get the value of the bit in the given positio. I will provide you some code for that to get in mind.
Code:
#include <stdio.h>
/* Get the bit value from a given position in a bitmap. */
int GetBit(char bitmap[], int BitPosition)
{
short int Index = 0;
unsigned char mask = 0x80;
int Byte =(int)(BitPosition / (8 *sizeof(char)));
int nrShifts = BitPosition % (8 * sizeof(char));
for(Index = 0; Index < nrShifts; Index++)
mask >>= 1;
return bitmap[Byte] & mask;
}
/* More usefull stuff. */
int IndexOfBit(char b[], int BitSize, int startIndex, int value)
{
unsigned char mask = 1 << (8 * sizeof(char) - 1 - (startIndex % 8));
char *p = b + (startIndex / (sizeof(char) * 8));
while(startIndex < BitSize)
{
if(!mask)
{
p++;
mask = mask = 1 << (8 * sizeof(char) - 1);
}
if (value && (mask & (unsigned char)*p) || !value && !(mask & (unsigned char)*p))
return startIndex; /* Found our bit. */
mask >>= 1;
startIndex++;
}
return -1;
}