Am I extracting these fields correctly using bitwise shift? (tag, index, offset)
问题 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