Possible Duplicate:
Weird behavior of right shift operator
Hello
Why both numbers from this function are printed the same? It is not a cyclic shift.
unsigned int i=0x89878685;
int main()
{
printf("0x%x\n", i);
printf("0x%x\n", i>>32);
}
$ ./a.out
0x89878685
0x89878685
Do all compilers work in this way?
Shifting a 32-bit integer by 32 bits is undefined behavior. The result is not predictable.
In C and C++ if the integer has
Nbits, you are only allowed to shift by less thenNbits. If you shiftNor more the behavior is undefined.In practice, when shifting a 32-bit integer, some platforms will simply interpret the shift count as a 5-bit value (discard any bits above the lower 5), meaning that
32will be interpreted the same way as0. This is apparently what happens on your platform. The value is not shifted at all.