retagged by
1,596 views
1 votes
1 votes

I just read that the logical and airthmatical left shift are same while there is a difference in case of right shift.

https://en.wikipedia.org/wiki/Bitwise_operation (under Logical shift)

Can understand how are they same. Like What is arithmetic left shift of 01001001? 

I would think it is 00010010 i.e. it tries to maintain the sign bit as is

On the other hand, the logical left shift by 1 pos would be 10010010

but both are not same. any example on that. 

retagged by

2 Answers

0 votes
0 votes

In left shift(logical+arithmetic) we just remove leftmost bit and add a 0-bit in the rightmost 

leftshift of 01001001 is 10010010

But in right-shift:

In logical : we just remove the rightmost bit and add 0-bit to the leftmost side.

In Arithmetic: We kept the sign bit as it was earlier, i,e. remove the rightmost bit and add earlier MSB to leftmost side.

0 votes
0 votes

Both arithmetic and logical left shift are same, and sign wont get changed unless there's an overflow.

This is because in 2's compliment representation the left side of the number will be filled with the sign bit itself (sign bit extension). Therefore left shift wont change the sign of the number, unless too many shifts are done.

 What is arithmetic left shift of 01001001?  

00000000000000000000000001001001 (+73)

After 1 left shift:

00000000000000000000000010010010 (+146)

Related questions

1 votes
1 votes
1 answer
1
Meenakshi Sharma asked Oct 22, 2016
5,064 views
what is the differernce between logical shift left (or right) and arithmetic shift left (or right)e.g if IN SOME REGISTER 10100110 IS STORED THEN WHAT WILL BE THE RESUL...
0 votes
0 votes
1 answer
3
rishu_darkshadow asked Nov 8, 2017
331 views
In C language, bitwise operation can be applied to which of the following operandsA. char B. int C. short, long ...
3 votes
3 votes
1 answer
4
dd asked Jun 27, 2017
522 views
#include <stdio.h int main() { unsigned int m = 0; m |= 0xA38; printf("%x\n",m|(m-1)); printf("%x\n",( (m|(m-1)) + 1 ) & m ); }Find the output ?