In special cases: Is & faster than %?
<p>I saw the chosen <a href="https://stackoverflow.com/a/40751824/1788806">answer</a> to this <a href="https://stackoverflow.com/questions/40751662/is-a-b-255-255-the-same-as-a-b-255">post</a>.</p>

<p>I was suprised that <code>(x &amp; 255) == (x % 256)</code> if x is an unsigned integer, I wondered if it makes sense to always replace <code>%</code> with <code>&amp;</code> in <code>x % n</code> for <code>n = 2^a (a = [1, ...])</code> and x being a positive integer. </p>

<p>Since this is a special case in which I as a human can decide because I know with which values the program will deal with and the compiler does not. <strong>Can I gain a significant performance boost if my program uses a lot of modulo operations?</strong></p>

<p>Sure, I could just compile and look at the dissassembly. But this would only answer my question for one compiler/architecture. I would like to know if this is in principle faster.</p>