So I know I can bit shift a mask of 0xFFFFFFFF by say 8 for example to get 0xFFFFFF00 & it with an address and get everything but the last 8 bits, but I would like to go the other way so I can grab the bottom end of an address with a mask like 0x000000FF, however bit shifting right wont work obviously. Any ideas?
Here is the code for the first type bit shift I mentioned.
public int Block_tag(int address, int block_size, int max_address) { int bit_shift = (int)Math.Log(block_size, 2); int bit_mask = max_address << bit_shift; return (address & bit_mask); } I could do it by hand with about 12 "If" statements but that isn't very clean.
Thanks!
address & 0x000000FF