In my book, I have an exercise that asks me to take an int x (like 0x12345678) and return another int with all but the least significant byte to be changed to FF (like 0xFFFFFF78).
So far so good. I implemented it as follows and it works:
1 2 3 4 5 6 7 8
#include <stdio.h>
int main()
{
int x = 0x12345678;
printf( " %.2x\n", x | 0xFFFFFF00 );
return 0;
}
The catch here is that it says your code should not assume any 'word size'.
Although our examples assume a 32-bit word size, your code should work for any word size >= 8