4.1.18

Bitwise Manipulation - Shifts

Test yourself on Bitwise Manipulation - Shifts

Test your knowledge with free interactive questions on Seneca — used by over 10 million students.

Bitwise Manipulation - Shifts

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

Logical shift right

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 ‘>>>’.
Logical shift left

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 ‘<<<’.
Arithmetic shift right

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 '>>'.
Arithmetic shift left

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 '<<'.
Circular shift

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
1

Components of a Computer

2

Software & Software Development

3

Exchanging Data

4

Data Types, Data Structures & Algorithms

5

Legal, Moral, Cultural & Ethical Issues

6

Elements of Computational Thinking

6.1

Thinking Abstractly

6.2

Thinking Ahead

6.3

Thinking Procedurally

6.4

Thinking Logically

6.5

Thinking Concurrently

7

Problem Solving & Programming

8

Algorithms

Practice questions on Bitwise Manipulation - Shifts

Can you answer these? Test yourself with free interactive practice on Seneca — used by over 10 million students.

  1. 1
  2. 2
  3. 3
Answer all questions on Bitwise Manipulation - Shifts

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