Write a function setbits(x,p,n,y) that returns x with the n bits that begin at position p set to the rightmost n bits of y, leaving the other bits unchanged.

Can someone please explain me how does this work:Code:unsigned setbits(unsigned x, int p, int n, unsigned y) { return (x & ((~0 << (p + 1)) | (~(~0 << (p + 1 - n))))) | ((y & ~(~0 << n)) << (p + 1 - n)); }

x & ((~0 <<(p+1))

p = 5;

char x = 0011 0100

0011 0100 &

0011 1111 // this set of bits?

---------------

0011 0100