Invert the Bits
PROBLEM :
Given a number (N) of 32 bit size you are required to print the number you get by inverting bits in its binary representation (i.e. 1 is made 0 and 0 is made 1). In other words we are required to negate(~) the number.
Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains an integer N.
Output:
For each test case in a new line print the required output.
Constraints:
1<=T<=100
1<=N<=10^8+9
Example:
Input:
2
4289384
1
Output:
4290677911
4294967294
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int main()
{
int t ;
cin>>t ;
while(t--){
unsigned int no ;
cin>>no ;
cout<<(~no)<<endl ;
}
return 0;
}
---------------------------------------------------------------------------------
Given a number (N) of 32 bit size you are required to print the number you get by inverting bits in its binary representation (i.e. 1 is made 0 and 0 is made 1). In other words we are required to negate(~) the number.
Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains an integer N.
Output:
For each test case in a new line print the required output.
Constraints:
1<=T<=100
1<=N<=10^8+9
Example:
Input:
2
4289384
1
Output:
4290677911
4294967294
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int main()
{
int t ;
cin>>t ;
while(t--){
unsigned int no ;
cin>>no ;
cout<<(~no)<<endl ;
}
return 0;
}
---------------------------------------------------------------------------------
Comments
Post a Comment