Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6829911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:33:22+00:00 2026-05-26T22:33:22+00:00

I am building a CPU cache emulator in C. I was hoping you could

  • 0

I am building a CPU cache emulator in C. I was hoping you could tell me if I am extracting these fields correctly:

The 32-bit address should be broken up as follows:

+---------------------------------------------------+
| tag (20 bits) | index (10 bits) | offset (2 bits) |
+---------------------------------------------------+

Here is my code to obtain the values for each:

void extract_fields(unsigned int address){

   unsigned int tag, index, offset;

   // Extract tag
   tag = address >> 12;

   // Extract index
   index = address << 20;
   index = index >> 22;

   // Extract offset
   offset = address << 30;
   offset = offset >> 30;

}

Any advice is much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:33:22+00:00Added an answer on May 26, 2026 at 10:33 pm

    It looks like your solution works, but it is often done a different way that is probably a bit more clear.

    For your example:

    // Shift off the lowest 12 bits, and mask off the higher ones
    tag = (address >> 12) & 0xFFFFF; 
    
    // Shift off the lowest 2 bits, and mask off the higher ones
    index = (address >> 2) & 0x3FF;
    
    // Shift off the lowest 0 bits, and mask off the higher ones
    offset = (address >> 0) & 0x3;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When building a Delphi 2009 component package, how do you specify which directory should
I was having some other problems with some ports building for the wrong CPU
I am building a small device with its own CPU (AVR Mega8) that is
I'm currently building a Java app that could end up being run on many
I've been doing some reading about the people building an emulator for the Wii
I am building a cache that has to store as much data as possible.
I'm building a network-distributed parallel processing application that uses a combination of CPU and
Building a new Mobile Web Platform for Mobile Users to purchase & download content
building a site using PHP and MySQL that needs to store a lot of
Building a Django app on a VPS. I am not very experienced with setting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.