Logical shift

Logical shift

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.

Logical shifts can be useful as efficient ways of performing multiplication or division of unsigned integers by powers of two. Shifting left by "n" bits on a signed or unsigned binary number has the effect of multiplying it by 2"n". Shifting right by "n" bits on an "unsigned" binary number has the effect of dividing it by 2"n" (rounding towards 0).

Because arithmetic right shift differs from logical right shift, many languages have different operators for them. For example, in Java and JavaScript, the arithmetic right shift operator is >>; whereas the logical right shift operator is >>>. (Java only has one left shift operator (<<), because arithmetic left shift and logical left shift have the same effect.)

C, however, has only one right shift operator, >>. Many C compilers choose which right shift to perform depending on what type of integer is being shifted; often signed integers are shifted using the arithmetic shift, and unsigned integers are shifted using the logical shift.

Example

If the bit sequence 0001 0111 were subjected to a logical shift of one bit position... (please refer images on right side)
* ...to the left would yield: 0010 1110
* ...to the right would yield: 0000 1011


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Shift — generally means to change (position). Shift may refer to: * Gear shift, to change gears in a car * Shift work, an employment practice * Shift (music), a change of level in music * Shift (magazine), a former Canadian technology and culture… …   Wikipedia

  • Shift Right — Jeu d instruction x86 Article détaillé : Jeu d instructions. Le jeu d instructions du x86 a subi de nombreux changements au cours du temps. La plupart d entre eux ne sont que des ajouts au jeu d instruction initial afin d apporter de… …   Wikipédia en Français

  • Logical Journey Of The Zoombinis — The Logical Journey of the Zoombinis Developer(s) Brøderbund Software Publisher(s) …   Wikipedia

  • Arithmetic shift — In computer programming, an arithmetic shift is a shift operator, sometimes known as a signed shift (though it is not restricted to signed operands). For binary numbers it is a bitwise operation that shifts all of the bits of its operand; every… …   Wikipedia

  • Circular shift — In combinatorial mathematics, a circular shift is the operation of rearranging the entries in a tuple, either by moving the final entry to the first position, while shifting all other entries to the next position, or by performing the inverse… …   Wikipedia

  • Paradigm shift — sometimes known as extraordinary science or revolutionary science, is the term first used by Thomas Kuhn in his influential 1962 book The Structure of Scientific Revolutions to describea change in basic assumptions within the ruling theory of sc …   Wikipedia

  • Attentional shift — happens because the human brain is limited in its ability to process information, and simultaneous processing cannot occur without a substantial cost.[1] Therefore, shifting of attention is necessary because it allows us to redirect attention to… …   Wikipedia

  • Quantifier shift — A logical fallacy in which the quantifiers of a statement are erroneously transposed. The change in the logical nature of the statement may not be obvious when it is stated in a natural language like English. Definition The fallacious deduction… …   Wikipedia

  • Bitwise operation — In computer programming, a bitwise operation operates on one or two bit patterns or binary numerals at the level of their individual bits. On most microprocessors, bitwise operations are sometimes slightly faster than addition and subtraction… …   Wikipedia

  • Fortran language features — This is a comprehensive overview of features of the Fortran 95 language, the version supported by almost all existing Fortran compilers. Old features that have been superseded by new ones are not described few of those historic features are used… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”