Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define bits(x) sizeof(x) * 8
- void showBits(unsigned x) {
- for (int i = bits(x) - 1; i >= 0; i--) {
- printf("%d", 1 & (x >> i));
- }
- puts("");
- }
- unsigned invert(unsigned x,unsigned p, unsigned n) {
- return x ^ (((1 << n) - 1) << (p - n + 1));
- }
- int main() {
- unsigned x, p, n;
- printf("x="); scanf("%u", &x);
- printf("p="); scanf("%u", &p);
- printf("n="); scanf("%u", &n);
- showBits(x);
- showBits(invert(x, p, n));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement