user7728: I'm trying to manipulate the ports of Arduino using C code. I have attached an LED to pin 8 and a tact switch to pin 13 (with a pull down resistor). The code works fine, and the results are printed on the screen. So, when the button is pressed, the byte PINB & (1 << PB5) equals 32, or 0b00100000. 
However, if I try to use
if( PINB &(1<<PB5) == 32){

or 
if( PINB &(1<<PB5) == 0b00100000){

the LED doesn't respond.
Here's the full code:
void setup() {
  DDRB |= 0b00011111; 
  Serial.begin(9600);
  }

void loop() {
  Serial.print("PINB &(1<<PB5)");
  Serial.println(PINB &(1<<PB5));

  if( PINB &(1<<PB5) ){
    PORTB |= (1<<PB0);
    }
  else{
    PORTB &= ~(1<<PB0);    
    }
  }

What am I missing?

user368: == has higher precedence than &, which means that your comparison will be performed incorrectly. But that doesn't matter, since you don't need to check if the port has a specific value, just if the appropriate bit is set.

7728: <p>I'm trying to manipulate the ports of Arduino using C code. I have attached an LED to pin 8 and a tact switch to pin 13 (with a pull down resistor). The code works fine, and the results are printed on the screen. So, when the button is pressed, the byte <code>PINB &amp; (1 &lt;&lt; PB5)</code> equals 32, or <code>0b00100000</code>. </p>

<p>However, if I try to use</p>

<pre><code>if( PINB &amp;(1&lt;&lt;PB5) == 32){
</code></pre>

<p>or </p>

<pre><code>if( PINB &amp;(1&lt;&lt;PB5) == 0b00100000){
</code></pre>

<p>the LED doesn't respond.</p>

<p>Here's the full code:</p>

<pre><code>void setup() {
  DDRB |= 0b00011111; 
  Serial.begin(9600);
  }

void loop() {
  Serial.print("PINB &amp;(1&lt;&lt;PB5)");
  Serial.println(PINB &amp;(1&lt;&lt;PB5));

  if( PINB &amp;(1&lt;&lt;PB5) ){
    PORTB |= (1&lt;&lt;PB0);
    }
  else{
    PORTB &amp;= ~(1&lt;&lt;PB0);    
    }
  }
</code></pre>

<p>What am I missing?</p>
 368: <p><code>==</code> has higher precedence than <code>&amp;</code>, which means that your comparison will be performed incorrectly. But that doesn't matter, since you don't need to check if the port has a <em>specific</em> value, just if the appropriate bit is set.</p>
