You are not logged in. Please login at www.codechef.com to post your questions!

×

What this line means?

 0 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?? asked 24 Jun '14, 20:42 2★keyser21 95●1●4●7 accept rate: 0%

One Answer:
 3 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 answered 24 Jun '14, 21:02 4★the65bit 1.1k●10●13●28 accept rate: 13% but if an assigning operation is done in if statement, wont it evaluate to true always ?? (24 Jun '14, 22:47) Yes, till the number becomes zero..For e.g 60, 30, 15, 7, 3, 1, 0. (24 Jun '14, 22:53) 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 (p) , and it be True if p is not zero and false otherwise . (24 Jun '14, 23:04) the65bit4★ Here, it checks for the number to be anything other than 0 and 1. (25 Jun '14, 06:32) p00r3★
 toggle preview community wiki:
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• link:[text](http://url.com/ "title")
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

question asked: 24 Jun '14, 20:42

question was seen: 769 times

last updated: 25 Jun '14, 06:32