Please Help my output is not getting correct: Reverse Bits question
hello @yashratnani6
a) u need to iterate upto 15 (becuase if u iterate till 31 then it will give u same A)
b) 
this will reset all other bit as well becuase in ur mask only one bit is set and rest all are zero , so when u will take and it will mark other set bit as 0
pls check ur updated code here->
unsigned int Solution::reverse(unsigned int A) {
unsigned int reversedNum = 0;
unsigned int mask1=0;
unsigned int mask2=0;
for(int i=0;i<=15;i++){
mask1 = 1<<i;
mask2 = 1<<(31-i);
if( ((A&mask1)>0) && ((A&mask2)==0)){
A = ((A | mask2) & (~mask1) );
}else if( ((A&mask1)==0) && ((A&mask2)>0)){
A = ((A|mask1) & (~mask2) );
}
}
return A;
}
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.