What this line means?

I found this line written in one of the solution I went through a solution

  if((P>>=1))
{
//some call to a function was done here
}

I don’t know meaning of this line, is it a check for even/odd, please explain and if possible mention any link where this bitwise operators tricks and tips are given??

It is the shorthand notation of P=P>>1 . >> is the right shift operator .

x>>y causes the binary representation of x to be shifted by the y digits to the right .

In the example you asked it is dividing the number by 2 and assigning to the number back .

For more information use : Right and Left Shift operator

3 Likes

but if an assigning operation is done in if statement, wont it evaluate to true always ??

Yes, till the number becomes zero…For e.g 60, 30, 15, 7, 3, 1, 0.

It won`t be to true always , it will evaluate to the value of the variable . For example in this case after the assignment is done it will become , if § , and it be True if p is not zero and false otherwise .

Here, it checks for the number to be anything other than 0 and 1.