I am currently working on a program to simulate a cache in C. I have been researching, I know how to set and test individual bits, but how could I extract x amount of bits from within the middle of a 64 bit hex address?
For example, I have a 64 bit hex address. The first 2 bits are dedicated for the block offset, the next 2 bits are dedicated for the set index, and the last 60 for the tag. How could I extract the first 2 bits into an unsigned integer? How could I extract the next 2 bits?
EDIT: This is just an example. I am hoping for a solution that will let you get any amount of bits anywhere in the address
SECOND EDIT: When I say first 2 bits, I mean the least significant bits. My apologies.