** Logical Shift** and

**are bit manipulation operations (bitwise operations).**

*Arithmetic Shift***Logical Shift**

- A
of one position moves each bit to the left by one. The vacant least significant bit (LSB) is filled with zero and the most significant bit (MSB) is discarded.*Left Logical Shift* - A
of one position moves each bit to the right by one. The least significant bit is discarded and the vacant MSB is filled with zero.*Right Logical Shift*

**Arithmetic Shift**

- A
of one position moves each bit to the left by one. The vacant least significant bit (LSB) is filled with zero and the most significant bit (MSB) is discarded. It is identical to Left Logical Shift.*Left Arithmetic Shift* - A
of one position moves each bit to the right by one. The least significant bit is discarded and the vacant MSB is filled with the value of the previous (now shifted one position to the right) MSB.*Right Arithmetic Shift*

Fig. 1 Left and Right Arithmetic Shift by One Bit

Arithmetic Shift operations can be used for dividing or multiplying an integer variable.

*Multiplication by left shift:*

The result of a Left Shift operation is a multiplication by 2^{n }, where n is the number of shifted bit positions.

*Example:*

Let’s take the decimal number 2 represented as 4 bit binary number *0010*. By shifting in to the left with one position we get *0100* which is 4 in decimal representation. If we shift it once more we get binary value *1000* which is 8 in decimal representation.

For unsigned representation, when the first “1” is shifted out of the left edge, the operation has overflowed. The result of the multiplication is larger than the largest possible.

Shifting left on signed values also works, but overflow occurs when the most significant bit changes values (from 0 to 1, or 1 to 0).

*Division by right shift:*

The result of a Right Shift operation is a division by 2^{n }, where n is the number of shifted bit positions.

*Example:*

If we have the binary number *01110101* (117 decimal) and we perform **arithmetic right shift** by 1 bit we get the binary number *00111010* (58 decimal). So we have divided the original number by 2.

If we have the binary number* 1010* (-6 decimal) and we perform **arithmetic right shift** by 1 bit we get the binary number *1101* (-3 decimal). So we have divided the original negative number by 2.

*Note: The examples above use two’s complement representation.*

### Was this article helpful?

**If you have any suggestions or questions, please leave a comment below.**

brad18/10/2017 at 20:06Hello! Thanks for the article, but the wording is unclear here:

“Let’s take the decimal number 2 represented as 4 bit binary number 0010. By shifting in to the right with one position we get 0100 which is 4 in decimal representation. If we shift it once more we get binary value 1000 which is 8 in decimal representation.”

Obviously a right shift will divide by 2^n, not multiply. I suggest you just say, By shifting left, we multiply

Yasen Stoyanov21/10/2017 at 17:48Hello brad,

Thanks for catching the mistake and providing us with a feedback. We will fix the wording in the article.

skywood06/06/2018 at 16:04for left arithmetic shift ,i think the MSB should retain to avoid overflow

Yasen Stoyanov06/06/2018 at 22:40Hello skywood,

By definition the left shift operation discards the MSB and this indeed may cause overflow which is undesired in almost every digital system. The solution is to implement additional logic (functionality) that saturates the result of the shift operation if an overflow has occurred.

The following article contains some basic concepts regarding overflow situations and how to detect them:

https://open4tech.com/overflow-digital-systems/

JudeJuicy22/06/2018 at 21:36I often visit your blog and have noticed that you don’t update it often. More frequent updates will give your

site higher authority & rank in google. I know that writing articles takes a lot of time, but you can always help yourself with miftolo’s tools which will shorten the time of creating an article to a few seconds.

Tama McGlinn17/08/2018 at 12:03The final 1-bit arithmetic right-shift doesn’t seem to actually divide by 2:

1010 -> 1101

If these are unsigned numbers (you didn’t specify), then 10 / 2 = 5, which is 0101, which would be the result of a logical 1-bit right-shift. If these are signed numbers, then -2 / 2 = -1, which is 1001.

This is all assuming signed magnitude representation, which worked for understanding all the preceding examples. Perhaps you meant 2’s complement?

1010 = -6, -6 / 2 = -3, which is 1101

My conclusion is that you should mention that this is all in 2’s complement, since your first examples handle unsigned numbers. Also, add the interpreted values into the final example to make it clearer that the result is correct.

Yasen Stoyanov18/08/2018 at 00:07Hello Tama,

Thank you for the feedback!

You are absolutely correct that it was not clear enough that we use 2’s complement in the last example. We have updated the article and it now incorporates your suggestion.

Royvia13/09/2019 at 17:19Great post.

Azamat03/03/2020 at 21:02hello thank you a lot for this blog. but i have question

-18 is 11101110 in 2s complement. what i will get if i use Arithmetic shift left by 2 bits for this?

Yasen Stoyanov04/03/2020 at 17:34Azamat,

When you shift 11101110 (-18 in 2’s complement) to the left by two positions you will get 10111000 (-72 in 2’s complement). Keep in mind that one additional left shift of this 8bit binary number 10111000 (-72) will cause an overflow and you should take precautions :)

WizZy16/03/2021 at 20:57Can i get overflow when i use logical shift left or logical shift right or arithmetic shift right ?

Yasen Stoyanov25/03/2021 at 21:19Yes, if you can get overflow when doing left shift (arithmetic and logic)