explanation of subroutine , bitshift , encoder

I have a maybe super dumb question, but what to do... will ask.

why it is neccesary to do these operations (and , bitshift):

(PIND&B0000100)>>2==HIGH

to verify the rotation direction of encoder?

full subroutine is below, full program here

void doEncoderMotor0(){
  if (((PIND&B0000100)>>2) == HIGH) {   // found a low-to-high on channel A; if(digitalRead(encoderPinA)==HIGH){.... read PB0
    if ((PINB&B0000001) == LOW) {  // check channel B to see which way; if(digitalRead(encoderPinB)==LOW){.... read PB0
      encoder0Pos-- ;         // CCW
    }
    else {
      encoder0Pos++ ;         // CW
    }
  }
  else                                        // found a high-to-low on channel A
  {
    if ((PINB&B0000001) == LOW) {   // check channel B to see which way; if(digitalRead(encoderPinB)==LOW){.... read PB0
                                              // encoder is turning 
      encoder0Pos++ ;          // CW
    }
    else {
      encoder0Pos-- ;          // CCW
    }
  }
}

why it is neccesary to do these operations (and , bitshift):

(PIND&B0000100)>>2==HIGH

The PIND register holds 8 bits. You can't just ask if the register is HIGH, because any one of the pins on that port could be HIGH. So, you need to mask the register with the pin that you care about, and then shift the result two places to the right, so the 0 or 1 in the 2nd position ends up in the 0th position. Then, you can compare that with HIGH.

PaulS , thank you, understood.

Is there any particular reason of this methos used to read pin status in this subroutine?
I mean, there is possibility to DigitaRead of single specific pin (instead of masking - shifting)

Using direct port manipulation is faster than digital read.

Thank you for answer.

went thru pros and cons in your link , and the answer is clear now.

There is a DigitalWriteFast library (includes a read function) which is almost as fast as port manipulation and may be easier to use.

...R