/* returns x with the n bits that begin at position p set to the * rightmost n bits of y, leaving the other bits unchanged. */ int setbits(int x, int p, int n, int y) { return (x & ~(~(~0 << n) << (p+1-n))) | (y & (~(~0 << n) << (p+1-n))); }