# Displacement operation

Time：2020-6-28
1. Original code, inverse code, complement code 1. Signed displacement operation (< and > >
Signed displacement operations are divided into < (shift left) and > > (shift right). These two kinds of displacements are for complement operation. Symbol bits are involved in displacement operation. Except for the negative number to fill 1 in the high position, the rest positions are filled with 0 in the right shift. No matter whether the left shift is positive or negative, the vacancy is filled with 0. Therefore, in the process of left shift, the negative number may become a positive number, and the positive number may become a negative number. Let me know. No difference between positive and negative: for even numbers, moving one bit to the right is generally divided by 2, moving one bit to the left is multiplied by 2, for odd numbers, moving one bit to the right is divided by 2-1, subtracting one because the extra bit is directly erased, and moving one bit to the left is also multiplied by 2. See the following example:
• 35

Original code: 00100011~~~~> > 1 (one digit to the right of complement): 00010001 = 17 (0 power of 2 + 4 power of 2)
Complement: 00100011~~~~< 1 (left shift of complement): 01000110 = 70
Inverse code: 00100011

• -35 (negative)

Negative numbers are special. Here is a special explanation:
(1) First, explain the original code:
We know that the original code of – 35 is 00100011, so the original code of – 35 is 10100011 (the highest bit is the sign bit, the sign bit of the negative number is 1, and the rest bits are the same as the positive number).
(2) And the irony:
The inverse of a negative number is the inverse of the original code of a negative number, so the inverse of – 35 is 11011100 (the high bit is still the same, the negative number is always 1, and the others are reversed).
(3) And complement:
The negative complement is the inverse plus one, so the – 35 complement is 11011101. So:

“> > 1” (one digit shift right of complement) = 11101110 (shift right of negative number, one digit shift high position), convert to original code = 10010010 (subtract one of complement, and then reverse) = – 18

“< 1” (shift complement one bit to the left) = 10111010, change to original code = 11000110 = – 70
————————————————
Copyright notice: This is the original article of CSDN blogger “Zhao Xiaoxiang Jasmine”, following CC 4.0 by-sa copyright agreement. Please attach the original source link and this notice for reprint.