Trying to understand this line of code

Can someone explain what the code below is doing? I know it's using a ternary operator.

!(PINB & 0b1000) ? Mouse.press(MOUSE_LEFT)   : Mouse.release(MOUSE_LEFT);

Specifically what does this do?

PINB & 0b1000

It tests bit 3 of the port PINB. ‘&’ is a logical-AND operator.

That is not the entire line of code, correct?

Blackfin:
It tests bit 3 of the port PINB. '&' is a logical-AND operator.

It's the bitwise AND operator.
Logical AND is '&&'.

Blackfin:
That is not the entire line of code, correct?

Why not?

Pieter

!(PINB & 0b1000) ? Mouse.press(MOUSE_LEFT) : Mouse.release(MOUSE_LEFT);

if( PINB & 0b1000 == 0)
{
Mouse.press(MOUSE_LEFT);
}
else
{
Mouse.release(MOUSE_LEFT);
}

Blackfin:
It tests bit 3 of the port PINB. '&' is a logical-AND operator.

That is not the entire line of code, correct?

So it's basically testing the particular pin if it's HIGH or LOW?

How do you know the Arduino pin that corresponds to that PINB bit 3?

Google PINB (your board)

PINB UNO (images) gives:

You tell us :slight_smile:

Ask Mr Google about "Arduino Uno Pinout"

PieterP:
It’s the bitwise AND operator.
Logical AND is ‘&&’.

Right. Thanks for the clarification.

Why not?

Yep, n/m. Didn’t look closely enough the first time.

Got it! Thank you guys!