title: Bit Shifting in Cache Simulation
body: <p>What is the formula for calculating the index and tag bits in</p>
  
  <ol>
  <li>Direct Mapped Cache</li>
  <li>Associative Cache</li>
  <li>Set Associative Cache</li>
  </ol>
  
  <p>I am currently using this formula for Direct Mapped: </p>
  
  <pre><code>#define BLOCK_SHIFT 5;
  #define CACHE_SIZE 4096;
  int index = (address &gt;&gt; BLOCK_SHIFT) &amp; (CACHE_SIZE-1);
  /* in the line above we want the "middle bits" that say where the block goes */
  long tag = address &gt;&gt; BLOCK_SHIFT; /* the high order bits are the tag */
  </code></pre>
  
  <p>Please tell me how many bits are shifted in Associative and Set Associative Cache..</p>