title: Is ((a + (b & 255)) & 255) the same as ((a + b) & 255)?
body: <p>I was browsing some C++ code, and found something like this:</p>
  
  <pre><code>(a + (b &amp; 255)) &amp; 255
  </code></pre>
  
  <p>The double AND annoyed me, so I thought of:</p>
  
  <pre><code>(a + b) &amp; 255
  </code></pre>
  
  <p>(<code>a</code> and <code>b</code> are 32-bit unsigned integers)</p>
  
  <p>I quickly wrote a test script (JS) to confirm my theory:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>for (var i = 0; i &lt; 100; i++) {
      var a = Math.ceil(Math.random() * 0xFFFF),
          b = Math.ceil(Math.random() * 0xFFFF);
  
      var expr1 = (a + (b &amp; 255)) &amp; 255,
          expr2 = (a + b) &amp; 255;
  
      if (expr1 != expr2) {
          console.log("Numbers " + a + " and " + b + " mismatch!");
          break;
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>While the script confirmed my hypothesis (both operations are equal), I still don't trust it, because 1) <a href="https://xkcd.com/221/" rel="noreferrer">random</a> and 2) I'm not a mathematician, <a href="https://i.imgur.com/Boq967h.png" rel="noreferrer">I have no idea what am I doing</a>.</p>
  
  <p>Also, sorry for the Lisp-y title. Feel free to edit it.</p>