title: Is it faster to use bit operators or if statements in C++?
body: <p>I was reading somewhere that it is faster to use bitwise operators instead of if statements where possible.  I am working on an image processing project and I have various methods for doing math on pixels.  For instance when I add a pixel I would check and make sure the sum does not go over the maximum value.  I changed it to be this...</p>
  
  <pre><code>    Pixel16 operator+(Pixel16 p) const noexcept
      {
          uint_fast32_t r = red + p.red;
          uint_fast32_t g = green + p.green;
          uint_fast32_t b = blue + p.blue;
          return Pixel16(r | -(r &gt; 0xffff), g | -(g &gt; 0xffff), b | -(b &gt; 0xffff));
      }
  </code></pre>
  
  <p>Do you guys think it is faster than writing statements like...</p>
  
  <pre><code>if(r &gt; 0xffff)
   r = 0xffff;
  </code></pre>
  
  <p>FYI red, green, and blue are member variables of type uint16_t</p>