| Sci-Tech Dictionary: logical shift |
(computer science) A shift operation that treats the operand as a set of bits, not as a signed numeric value or character representation.
| Sci-Tech Dictionary: logical shift |
(computer science) A shift operation that treats the operand as a set of bits, not as a signed numeric value or character representation.
| 5min Related Video: Logical shift |
| Wikipedia: Logical shift |
| Language | Left | Right |
|---|---|---|
| C/C++ (unsigned types only) | << | >> |
| Delphi | shl | shr |
| Java, JavaScript | << | >>> |
| Ocaml | lsl | lsr |
| Standard ML | << | >> |
| VHDL | sll | srl |
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 2n. Shifting right by n bits on an unsigned binary number has the effect of dividing it by 2n (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.
If the bit sequence 0001 0111 were subjected to a logical shift of one bit position... (please refer images on right side)
This entry is from Wikipedia, the leading user-contributed encyclopedia. It may not have been reviewed by professional editors (see full disclaimer)
| shift left (or right) logical (computer jargon) | |
| quantitative revolution | |
| history of geography |
Copyrights:
![]() | Sci-Tech Dictionary. McGraw-Hill Dictionary of Scientific and Technical Terms. Copyright © 2003, 1994, 1989, 1984, 1978, 1976, 1974 by McGraw-Hill Companies, Inc. All rights reserved. Read more | |
![]() | Wikipedia. This article is licensed under the GNU Free Documentation License. It uses material from the Wikipedia article "Logical shift". Read more |