So I am extremely confused with using bitwise shifts used to extract the bytes from an integer. I find that if I do something like this...
int i = 512; i & 0xFF; // this gives me the first byte
That must mean
i & 0xFF gives me the first byte that is stored in memory. In other words,
i & 0xFF is the first of the four bytes i consists of stored at the lowest memory address. Next, I think that
i << 8 & 0xFF will then shift everything left by 8 bits and giving me the second byte. However, it is actually the opposite and only
i >> 8 & 0xFF gives me the next byte. I do not understand why this is true. To me, it makes the most sense to left shift to get the next byte so why do I need to right shift by 8 to get the proceeding byte?