标签:nbsp use 比特 sign put scanf signed 取反 can
输入:无符号数,指定bit位
输出:指定的bit位被置1的值
例如:输入 891 7 输出 1019
1 #include <stdio.h> 2 #include <stdlib.h> 3 int main(void) 4 { 5 unsigned int c, tmp; 6 int d; 7 while (1) 8 { 9 scanf("%d%d", &c, &d); 10 if ((d >= 0) && (d <= 31)) 11 { 12 tmp = c; 13 tmp &= ~(1 << d); //(0000 0000 0000 0001)左移d位(0000 0000 1000 0000)取反(1111 1111 0111 1111)& 14 // (0000 0000 0000 0001) 15 // (0000 0000 1000 0001)| 16 tmp |= 1 << d; // (0000 0000 1000 0000) 17 // (0000 0000 1000 0001) 18 c = tmp; 19 printf("%d\n", c); 20 } 21 else 22 { 23 printf("input error\n"); 24 } 25 } 26 27 system("pause"); 28 return 0; 29 }
标签:nbsp use 比特 sign put scanf signed 取反 can
原文地址:https://www.cnblogs.com/dog-pi/p/10175661.html