You need to change your comparator for each bit
unsigned long getFreeCluster()
{
...
bool found = false;
for (int i = 0; !found && (i < 2048); ++i)
for (int b = 0; b < 8; ++b)
if (cluster[i] & (1 << b) != 0)
{
position = i * 8 + b;
found = true;
break;
}
}
If you are only looking for the first bit = 1, this might be faster:
unsigned long getFreeCluster()
{
...
bool found = false;
for (int i = 0; !found && (i < 2048); ++i)
if (cluster[i] != 0)
for (int b = 0; b < 8; ++b)
if (cluster[i] & (1 << b) != 0)
{
position = i * 8 + b;
break;
}
}