/*
 * This C procedure determines which bits are set in a 32-bit long integer
 * and fills up an array with the position numbers (zero based) of the
 * set bits.  The number of bits set, and consequently the number of valid
 * entries in the array, is returned.
 */
#define BIT_SETSIZE	32
typedef	unsigned long	bit_set;

int which_bits_set(bits_are_set, set_of_bits)
int bits_are_set[]; bit_set set_of_bits;
{
	int j, m;

	m = 0;
	for (j=0; j<BIT_SETSIZE; j++) {
		if (set_of_bits == 0) break;
		if (set_of_bits & 1) {bits_are_set[m] = j; m++;}
		set_of_bits = set_of_bits >> 1;
	}
	return(m);
}
