previous | start | next

Right Shift (cont.)



int x = 0x800400F8;

In binary x's value:  1000 0000 0000 0100 0000 0000 1111 1000
          ---------- ----------------------------------------
          x >> 3   :  1111 0000 0000 0000 1000 0000 0001 1111

In hex the value of x >> 3 is: 0xF000801F

But,

int y = 0x700400F8;

In binary y's value:  0111 0000 0000 0100 0000 0000 1111 1000
          ---------- ----------------------------------------
          y >> 3   :  0000 1110 0000 0000 1000 0000 0001 1111

In hex the value of y >> 3 is: 0x0E00801F

The arithmetic right shift operation for signed int's, x >> n, is performed by
starting with a copy of the bits of x, then shifting them right n
bits. The rightmost n bits have nowhere to go and are discarded. The
leftmost n bits are filled with the a copy of the left most bit of x. 


previous | start | next