Sir , little bit confused that why we use (no=no>>1) this statement , please explain !!
Confused in a statement , please help !1
hi @piyushkumar999999 this is >>
right shift operator. In the bit representation of a number, it shifts all the bits to right.
if i write x >> y
it will shift the bits in x by y positions.
for eg 5 = 00000101 in binary
5 >> 1 means all bits will be shifted to right by 1 place, so the number becomes 00000010 which i s 2 in decimal form.
Effectively, x >> y evaluates to x / (2 ^ y)
so if y = 1, like in the statement above
it means no = no/2
bitwise operators are faster than arithmetic operators hence this approach is used
Mam , i knew this concept but i am unable to put the logic in this code , to please elaborate by taking the example of the above code .
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.