For signed right, if it is negative, at the time of the first storage represents a sign bit, a value of 1, the value is a negative shift in the shift process, the high bit of 1, if the sign bit is 0, indicates is a positive number, in the process of shifting the high bit to zero, provided both are symbols remain unchanged:
For negative right: in memory as a negative two's complement form is present, first of all determined according to the original negative negative complement code (sign bit unchanged, the remaining bits according to the original code negated plus 1), and then to ensure that the sign bit change, to the remaining X-bit bit to the right, in the process of moving, the high bit of 1. the like after the completion of the shift, the sign bit then remains unchanged, the remaining bitwise adding 1, to give the shift the code number corresponding to the original. It is also desired.
Example 1:
Signed right shift 4 -100.
-100 original code: 1,000,000,000,000,000 0,000,000,001,100,100
-100 Complement: guaranteed symbol bit constant plus a rest position negated
11111111 11111111 11111111 10011100
Right 4: 1 at a high fill
11111111 11111111 11111111 11111001
After the shift complement form is completed, the result is not the result of a shift, to write the original code is that we ask according to the results of complement. , As follows:
Retain the sign bit, and then bitwise
10000000 00000000 00000000 00000110
Then add 1, is also desired number of the original code:
10000000 00000000 00000000 00000111
All results: -7
Example 2:
-100 unsigned right shift 4.
-100 original code: 1,000,000,000,000,000 0,000,000,001,100,100
-100 Complement: guaranteed symbol bit constant plus a rest position negated
11111111 11111111 11111111 10011100
Unsigned right shift 4: 0 at a high fill
00001111 11111111 11111111 11111001
It is also desired: 268 435 449
Summary: The positive left and right, a negative unsigned right shift, is the resulting displacement of the corresponding complement, at a high level up to 0.
Negative right, high bit 1's complement is then added bitwise to 1.
----------------
Disclaimer: This article is CSDN bloggers "and so you read the landscape" of the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/king_msky/article/details/17221973