4.1.18

Bitwise Manipulation - Shifts

Test yourself

Bitwise Manipulation - Shifts

Bitwise manipulation is the act of modifying data by changing the bits within individual bytes.

Illustrative background for Logical shift rightIllustrative background for Logical shift right ?? "content

Logical shift right

  • A logical shift right moves each of the bits in a byte one place to the right.
  • The ‘least significant bit’ (LSB) on the right is lost and the empty space for the ‘most significant bit’ (MSB) is filled with a ‘0’.
    • For example, 1 0 1 0 1 0 0 0 \rightarrow 0 1 0 1 0 1 0 0
  • A logical shift right is identified with a triple chevron ‘>>>’.
Illustrative background for Logical shift leftIllustrative background for Logical shift left ?? "content

Logical shift left

  • A logical shift left moves each of the bits in a byte one place to the left.
  • The MSB on the left is lost and the empty space for the LSB is filled with a ‘0’.
    • For example: 1 0 1 0 1 0 0 0 \rightarrow 0 1 0 1 0 0 0 0
  • A logical shift left is identified with a ‘<<<’.
Illustrative background for Arithmetic shift rightIllustrative background for Arithmetic shift right ?? "content

Arithmetic shift right

  • Arithmetic shifts are almost the same as logical shifts, except the MSB is a sign bit and always remains the same.
  • An arithmetic shift right has the following result:
    • 1 0 1 0 1 0 0 0 \rightarrow 1 0 0 1 0 1 0 0
    • This has the effect of dividing the original number by 2.
  • An arithmetic shift right is identified with a '>>'.
Illustrative background for Arithmetic shift leftIllustrative background for Arithmetic shift left ?? "content

Arithmetic shift left

  • An arithmetic shift left has the following result:
    • 1 0 1 0 1 0 0 0 \rightarrow 1 1 0 1 0 0 0 0
    • This has the effect of multiplying the original number by 2.
  • An arithmetic shift left is identified with a '<<'.
Illustrative background for Circular shiftIllustrative background for Circular shift ?? "content

Circular shift

  • With a right circular shift, the same procedure applies.
  • However, instead of losing the LSB in a right shift, it ‘wraps around’ and becomes the MSB.
    • 1 0 1 0 1 0 0 0 \rightarrow 0 1 0 1 0 1 0 0
  • Similarly, with a left circular shift, the MSB becomes the new LSB.
    • 1 0 1 0 1 0 0 0 \rightarrow 0 1 0 1 0 0 0 1

Jump to other topics

1Components of a Computer

2Software & Software Development

3Exchanging Data

4Data Types, Data Structures & Algorithms

5Legal, Moral, Cultural & Ethical Issues

6Elements of Computational Thinking

6.1Thinking Abstractly

6.2Thinking Ahead

6.3Thinking Procedurally

6.4Thinking Logically

6.5Thinking Concurrently

7Problem Solving & Programming

8Algorithms

Unlock your full potential with Seneca Premium

  • Unlimited access to 10,000+ open-ended exam questions

  • Mini-mock exams based on your study history

  • Unlock 800+ premium courses & e-books

Get started with Seneca Premium