Why doesn't bitwise shift work for 32 bits shift? (X>>32) - page 2

 

And even better ;-)))

int n=0xFEDCBA98;
int b=40;
Alert("n               :  "+ n                 +"  "+IntegerToHexString(n));
Alert("b               :  "+ b                 +"  "+IntegerToHexString(b));
Alert("n>>40           :  "+ n>>40             +"  "+IntegerToHexString(n>>40));
Alert("n>>b            :  "+ n>>b              +"  "+IntegerToHexString(n>>b));
Alert("0xFEDCBA98>>40  :  "+ 0xFEDCBA98>>40    +"  "+IntegerToHexString(0xFEDCBA98>>40));
Alert("0xFEDCBA98>>b   :  "+ 0xFEDCBA9>>b      +"  "+IntegerToHexString(0xFEDCBA98>>b));
Alert("n>>-40          :  "+ n>>(-40)          +"  "+IntegerToHexString(n>>(-40)));
Alert("n>>-b           :  "+ n>>(-b)           +"  "+IntegerToHexString(n>>(-b)));
Alert("0xFEDCBA98>>-40 :  "+ 0xFEDCBA98>>(-40) +"  "+IntegerToHexString(0xFEDCBA98>>(-40)));
Alert("0xFEDCBA98>>-b  :  "+ 0xFEDCBA98>>(-b)  +"  "+IntegerToHexString(0xFEDCBA98>>(-b)));

... gives:

Alert: n               :  -19088744  FEDCBA98
Alert: b               :  40  00000028
Alert: n>>40           :  16702650  00FEDCBA
Alert: n>>b            :  16702650  00FEDCBA
Alert: 0xFEDCBA98>>40  :  -74566  FFFEDCBA
Alert: 0xFEDCBA98>>b   :  1043915  00FEDCBA
Alert: n>>-40          :  254  000000FE
Alert: n>>-b           :  254  000000FE
Alert: 0xFEDCBA98>>-40 :  -2  FFFFFFFE
Alert: 0xFEDCBA98>>-b  :  254  000000FE

Positive shift:

variable >> literal ==> binary shift (modulo)
variable >> variable ==> binary shift (modulo)
literal >> literal ==> logical shift (modulo + sign propagation)
literal >> variable ==> binary shift (modulo)

Negative shift: same logic but returns bit overflow of revert shift

Moreover to compare result lines 3 and 4 with line 6 : 0x00FEDCBA value is not translated the same way ... actually 1043915 = 0x000FEDCB.

Enjoy !

Why those differences?

Reason: