1 #include<stdio.h>
2 int turn_n(int ,int);
3 int main(void)
4 {
5 int test,a=-15,b=0xfffffffe,c=15;
6 printf("%x
%d
%x
",a,b,c);
7 test=turn_n(-15,4);
8 printf("%d
",test);
9 return 0;
10 }
11 int turn_n(int num,int bits)
12 {
13 int mask=0;
14 int bitval=1;
15 while(bits-->0)
16 {
17 mask |=bitval;
18 bitval <<=1;
19 }
20 return num^mask;
21 }