移位操作行为

移位

算术移位

arithmetic shift left <-- 移位空缺填0
arithmetic shift right <-- 移位空缺填原MSB,即符号位

逻辑移位

logic shift left
logic shift right

移位产生的空缺均填0。

循环移位

Rotate left
Rotate right

从一端移出,从另一端移入。

0b11010001

+---+---+---+---+---+---+---+---+
| 1 | 1 | 0 | 1 | 0 | 0 | 0 | 1 |
+---+---+---+---+---+---+---+---+

// 循环右移1bit,从LSB捞一位到MSB
+---+---+---+---+---+---+---+---+
| 1 | 1 | 1 | 0 | 1 | 0 | 0 | 0 |
+---+---+---+---+---+---+---+---+

// 逻辑右移1bit
+---+---+---+---+---+---+---+---+
| 0 | 1 | 1 | 0 | 1 | 0 | 0 | 0 |
+---+---+---+---+---+---+---+---+

// 算数右移1bit,复制原MSB
+---+---+---+---+---+---+---+---+
| 1 | 1 | 1 | 0 | 1 | 0 | 0 | 0 |
+---+---+---+---+---+---+---+---+

你可能感兴趣的:(编程语言,#,C,c语言)