what is the difference between logical right shift and arithmetic right shift?
Arithmatic right shift duplicates the sign-bit. Logical shift ignores the sign bit and the left-most bit becomes 0
.
Example
8-bit right-shift to keep things simple.
Example 1
11100101
Original bits
11110010
Arithmetic right-shift
01110010
Logical right-shift
Example 2
00011101
Original bits
00001110
Arithmetic right-shift
00001110
Logical right-shift
Note that both operations are the same when the sign bit is 0
.
One (arithmetic shift) preserves sign (by filling in the vacated left-most bit position with a duplicate of what was previously there); the other does not (logical shift) and instead always fills in with zeroes.
LSR shifts the bits to the right and fills the MSb with 0. ASR shifts the bits to the right and fills the MSb with whatever was there before the shift, which preserves the "divide by 2" mechanism for signed numbers.