We are getting number n in 32 bit and we need to flip all the bits and then write its equivalent decimal.
But my code not working please tell my mistake
Flipping bits of a number in 32bit form and writing it's decimal form
hello @coderajay03
put n&1 inside brackets. i,e if( (n&1) == 0 )
if still it fails , then pls share the question link with me
still getting wrong for test case q=1 and n=9
answer should be 4294967286 but I’m getting 4294967295
… … … …
after making the changes that i suggested above it is working fine
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int q;
cin>>q;
while(q--){
long long int n,sum=0;
cin>>n;
int i=0;
while(i<=31){
if((n&1)==0)//if the and is 0 that means this bit will be flipped and will make change in decimal since'1'
sum+=pow(2,i);
n=n>>1;
i++;
}
cout<<sum<<endl; //printing equivalent decimal
}
}

yes don’t know why When I ran it on coding blocks ide I was getting the absurd result I submitted it on hackerrank and it passed. And one more little doubt I am not able to solve questions on codeforces therefore doing hackerrank is it good or I should try to sustain on codeforces help would be appreciated…
in starting everyone faces issue just keep practicing and upsolving (solving that question which u r not able to solve during contest).
u will get better with the time
yeah bro all online judges are good . hackerrank is more begineer friendly .
its upto u which judge u like. just stick to it and practice hard
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.