I'm attempting to shift a 16 bit address to get a set ID for a cache simulator in C, but when I try and bit shift right I get an extra 1 stuck onto my number.
I have the number 0010100010011001. I then shift to the left 3 digits to get 0100010011001000. So far so good. However, I then try to shift to the right 6 digits and end up with 0000010100010011 instead of 0000000100010011. All of my ints are unsigned, and it only adds one 1 when I try and shift.
My code to try and shift is the following. In my example, tag_size is 3 and b is 6.
unsigned int temp = addr << tag_size;
unsigned int temp1 = temp >> b;
unsigned int setid = temp1 >> tag_size;