why to get the MSB of a 32 bit integer do we need to do (number rightshift 31) &1 ?why not 32 in place of 31 while rightshifting?
About the bitmasking process
hello @Senjuti256
positioning is 0 based. 32th bit (from right) is at 31 position .
thats why we do number >> 31 ( to get 32th bit at 1st place).
for example -> 101 (to get 1st bit ) we do 101 >> 0
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.
@Senjuti256 you have revoked your doubt instead of resolved. If your doubt is still not resolved, you can ask it.
when we do (101 rightshift 0) what does happen actually I mean the number won’t become 010 after the right shift operation thn how can we check whether the 1st bit is set or not?
If you want to check that the ith (x) bit is set or not, then do x&1 . If it gives 1 then it is set , if it’s 0 then it’s not set.
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.