For example, a signed bit of the 8-bit binary number 11001101, the logical right shift regardless of the sign bit, if the move one becomes 01100110. The arithmetic right moves to the tube sign bit, the right one becomes 10100110.
Logical left shift = arithmetic left shift, right unified add 0
Logical right SHIFT, left unified add 0
Arithmetic is shifted right, and the number added to the left is related to the symbol
Attached code:
intSraintXintk) { intXSRL = (unsigned) x >>K; intW =sizeof(int) <<3; returnXsrl |= (-1<< (wk));} Unsigned srl (unsigned x,intk) {unsigned Xsra= (int) x >>K; intW =sizeof(int) <<3; returnXsra &= ~ (-1<< (W-k));}
e.g:1010101010, where [] bit is the number added
Shift logic left one: 010101010[0]
Arithmetic left shift one: 010101010[0]
Logical right SHIFT one: [0]101010101
Arithmetic right shift one: [1]101010101
Logical Right Shift function SRL () and arithmetic right shift function SRA () (GO)