AND a mask to address (lower bits needed) C#
<p>So I know I can bit shift a mask of 0xFFFFFFFF by say 8 for example to get 0xFFFFFF00 &amp; it with an address and get everything but the last 8 bits, but I would like to go the other way so I can grab the bottom end of an address with a mask like 0x000000FF, however bit shifting right wont work obviously. Any ideas? </p>

<p>Here is the code for the first type bit shift I mentioned.</p>

<pre><code>public int Block_tag(int address, int block_size, int max_address)
    {
        int bit_shift = (int)Math.Log(block_size, 2);
        int bit_mask = max_address &lt;&lt; bit_shift;
        return (address &amp; bit_mask);
    }
</code></pre>

<p>I could do it by hand with about 12 "If" statements but that isn't very clean. </p>

<p>Thanks!</p>
