lets see this example
consider this value 1111 1111 1111 1111
if your compiler is 16 bit you did right shift
value will become 1111 1111 1111 1110
if your compiler is 32 bit and you did right shift
value will become 0000 0000 0000 0001 1111 1111 1111 1110
you did the right shift of same value but you will get different result depending up on your compiler.
use %x to print the hexa decimal notation of decimal value.
see this code :
#include <stdio.h>
main()
{
int y=-01;
printf("%d\n",y);
printf("%x\n",y);
y<<=3;
printf("%d\n",y);
printf("%x\n",y);
y>>=3;
printf("%d\n",y);
printf("%x\n",y);
y=127;
printf("%d\n",y);
printf("%x\n",y);
y<<=3;
printf("%d\n",y);
printf("%x\n",y);
y>>=3;
printf("%d\n",y);
printf("%x\n",y);
y=32767;
printf("%d\n",y);
printf("%x\n",y);
y<<=3;
printf("%d\n",y);
printf("%x\n",y);
y>>=3;
printf("%d\n",y);
printf("%x\n",y);
getchar();
}
OUTPUT ON 64-bit machine :
-1
ffffffff
-8
fffffff8
-1
ffffffff
127
7f
1016
3f8
127
7f
32767
7fff
262136
3fff8
32767
7fff
OUTPUT ON 32-bit machine :
-1
ffffffff
-8
fffffff8
-1
ffffffff
127
7f
1016
3f8
127
7f
32767
7fff
-8
fffffff8
-1
ffffffff
when reaches to maximum value of 32 bit signed integers , you will find the compiler dependency on shifting.
here 8-bit signed integers explained with 1's and 2's compliment representation
Signed number representations