title: C Virtual to physical address mapping
body: <p>I am beginner in C, I am trying to convert virtual addresses to physical.</p>
  
  <p>My code so far, but don't know how to the translation.</p>
  
  <p>I am using <code>4Kb</code> pages.</p>
  
  <p>The conversion I know is: for givin address: 0x12C000, the last three numbers won't be changed 000 and the remaining 12C will be converted, and then combine the fixed numbers with the converted. correct me if wrong, and how do I do taht in code ?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main() {
  
      uint page_table[512] = { 0 };
      page_table[200] = 0x1234;
      page_table[300] = 0x2345 ;
      page_table[511] = 0x8000 ;
  
      uint page_table_size = (sizeof(array)/sizeof(array[0]));
      uint page_size_bits 12 // // 2^12 = 4KB;
      uint mask_offset ((1&lt;&lt;page_size_bits)-1);
  
      // example of correct outputs:
  
      uint log_addr = 0x12C000;
  
      /* should be 0x2345000 */
      uint correctoutput; 
  
      log_addr = 0x12CFFF;
  
      /* should be 0x2345FFF */
      correctoutput; 
  
      log_addr = 0x1FF84A;
  
      /* should be 0x800084A */
      correctoutput; 
  
  }
  </code></pre>