/* returns x with the n bits that begin at position p inverted, * leaving the others unchanged */ int invert(int x, int p, int n) { return x ^ (~(~0 << n) << (p+1-n)); }