#include <stdio.h>

// Count the number of zeros in a specific amount of bits starting at a specific offset
// value is the original value
// offset is the offset in bits
// bits is the number of bits
unsigned int count_zeros(unsigned int value, unsigned int offset, unsigned int bits)
{
    // Get the bits we're interested in the rightmost position
    value >>= offset;

    unsigned int counter = 0;  // Zero-counter
    for (unsigned int i = 0; i < bits; ++i)
    {
        if ((value & (1 << i)) == 0)
        {
            ++counter;  // Bit is a zero
        }
    }

    return counter;
}

int main(void)
{
	printf("Result of count_zeros(0xa5, 2, 4) = %u\n", count_zeros(0xa5, 2, 4));
}
