Question: Write a function F(x, p, n, y) such that it returns x with the n bits that begin at position p (from LSB) set to the rightmost n bits of y.

Do not change other bits. Both x and y are unsigned integers.


Solution: f (x, p, n, y)
{
return (x & ~(~(~0 << n) << p)) | ((y & ~(~0 << n)) << p);
}