/* The caller can pass in *p if it wants to keep track of the most recent number of parity bits added. This allows the function to start the calculation at the last place.  */
static unsigned int calc_code_bit(unsigned int i, unsigned int *p_cache)
/* The caller can pass in *p if it wants to keep track of the most recent number of parity bits added. This allows the function to start the calculation at the last place.  */
static unsigned int calc_code_bit(unsigned int i, unsigned int *p_cache)
{
	unsigned int b, p = 0;
	b = i + 1;
	if (p_cache)
		p = *p_cache;
        b += p;
	for (; (1 << p) < (b + 1); p++)
		b++;
	if (p_cache)
		*p_cache = p;
	return b;
}