Logical shift
From Wikipedia, the free encyclopedia
In computer science, a logical shift is a shift operator that shifts all the bits of its operand. Unlike an arithmetic shift, a logical shift does not preserve a number's sign bit or distinguish a number's exponent from its mantissa; every bit in the operand is simply moved a given number of bit positions, and the vacant bit-positions are filled in, generally with zeros (compare with a circular shift).
A logical shift is often used when its operand is being treated as a sequence of bits rather than as a number.
The left shift has a useful side effect: shifting left by n bits on a signed or unsigned binary number has the effect of multiplying it by 2n.
[edit] Example
If the bit sequence 0001 0111 were subjected to a logical shift of one bit position... (see images to right)
- ...to the left would yield: 0010 1110
- ...to the right would yield: 0000 1011