编写reverse函数,返回将无符号整数x的第pos位取反后的值。
1、
#include <stdio.h>
unsigned reverse(unsigned x, int pos)
{
if(x >> pos & 1U)
return (x & (~(1 << pos)));
else
return (x | 1 << pos);
}
int main(void)
{
unsigned x;
int n;
puts("please input two nonnegatives.");
printf("x = "); scanf("%u", &x);
printf("n = "); scanf("%d", &n);
printf("result: %u
", reverse(x, n));
return 0;
}