Output the integer by flipping bits in its binary representation (i.e. unset bits must be set, and the set bits must be unset )
Input:
3
2147483647
1
0
Output:
2147483648
4294967294
4294967295
Implementation:
Input:
3
2147483647
1
0
Output:
2147483648
4294967294
4294967295
Implementation:
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { int t,n; /* get the number of test cases */ scanf("%d",&t); while(t--) { /* get the unsigned integer value */ scanf("%d",&n); /* bitwise complement operator will flip the bits in bitwise */ /* ~n = -(n+1) */ /* the signed result will be rotated & converted to unsigned integer representation */ printf("%u\n",~(n)); } return 0; }