previous | start | next

Right shift for the unsigned int data type



unsigned int x = 0x800400F8;

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

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

The right shift operation for unsigned 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 0's. Filling the leftmost n bits with
0's is also called "logical right shift".


previous | start | next