Bit twiddling question for buttons (PIND & (1<<PD3)

I learned this method at school for reading the current pin values using bit twiddling (pull up resistor)

if (PIND & (1<<PD3)){
      //button hasnt been pressed do nothing}
else{
      //button pressed do something
}

however, I never understood how to translate this line into English:
if (PIND & (1<<PD3))"

what exactly is it saying?

"If PIND and 1 has been left shifted into PD3"

I was wondering if someone could further refine my translation. Thank you!

Close :slight_smile: , but no.

What it really means:

"1 is leftshifted PD3 places and then bitwise anded with PIND. If the result of the operation in the previous sentence is nonzero, then button hasn't been pressed. Else, the button has been pressed."

For instance:

If PD3 = 00000011 and PIND = 10000000, then the following happens:

00000001 becomes leftshifted by 3 places resulting in 00001000. Next, 00001000 is bitwise anded with 10000000, BUT, since the answer to the anding is 00000000, the argument in the if statement is false, so the button has been pressed.

If PD3 = 00000011 and PIND = 00001000, then the following happens:

00000001 becomes leftshifted by 3 places resulting in 00001000. Next, 00001000 is bitwise anded with 00001000, AND, since the answer to the anding is 00001000, the argument in the if statement is true, so the button hasn't been pressed.

PD3

The correct name is...

PIND3
if ((PIND & 0b00001000) == 0b00001000){
// PIND bit3 is high
}
else {
// PIND bit3 is low
}

WHOA! I get it, each explanation above helped piece together the puzzle in my mind. Thank you all for your advice.