I'm trying to do the following:
Write a func
setbits(x,p.n,y)
that returnsx
withn
bits that begin at positionp
set to the rightmostn
bits ofy
,leaving the other bits unchanged?
I tried it like this but not getting correct answers. Can anyone tell where I am wrong?
unsigned setbits(unsigned x,int p,int n,unsigned y)
{
return (x>>p & (y|(~0<<n)));
}