I have a test program like this:
int main()
{
unsigned n = 32;
printf("ans << 32 = 0x%X
", (~0x0U) << 32);
printf("ans >> 32 = 0x%X
", (~0x0U) >> 32);
printf("ans << n(32) = 0x%X
", (~0x0U) << n);
printf("ans >> n(32) = 0x%X
", (~0x0U) >> n);
return 0;
}
It produces the following output:
ans << 32 = 0x0 ... (1)
ans >> 32 = 0x0 ... (2)
ans << n(32) = 0xFFFFFFFF ... (3)
ans >> n(32) = 0xFFFFFFFF ... (4)
I was expecting (1) and (3) to be the same, as well as (2) and (4) to be the same.
Using gcc version: gcc.real (Ubuntu 4.4.1-4ubuntu9) 4.4.1
What is happening?
See Question&Answers more detail:os