In the K&R book in chapter 2.9, I am stuck on understanding this sample function getbits()
getbits(x,p,n)
Returns the (right-adjusted) n-bit field of x that begins at position p. Here's the function body
/* getbits: get n bits from from position p */
unsigned getbits(unsigned x, int p, int n)
{
return (x >> (p+1-n)) & ~(~0 << n);
}
I am actually not facing problems with the bitwise operators but I can't actually get the question. I am stuck on understanding the question mainly not solving it. Ultimately "What do we need to find in this function".