Getting modulus from `&`
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/10097534/why-is-modulo-operator-necessary">Why is modulo operator necessary?</a>  </p>
</blockquote>



<p>I need help understanding how does <code>&amp;</code> give the modulus? I am <a href="http://stackoverflow.com/questions/12594208/c-program-to-determine-levels-size-of-cache">working on an assignment</a> to use memory access times to determine the cache sizes. Currently I am getting wierd results for the L3 size. I think it has something to do with <code>&amp;</code> only working well for powers of 2, or something like that? So I want to understand how it actually works</p>

<pre><code>lengthMod = 1024/sizeof(int) - 1;
for (unsigned int k = 0; k &lt; REPS; k++) {
    data[(k * 16) &amp; lengthMod]++;
}
</code></pre>

<p>Will <code>&amp;</code> always work? Or does it only work with some values? What actually happens for other values? </p>
