# 定点数的运算 —— 逻辑移位、算术移位、循环移位

### 一、逻辑移位&#x20;

逻辑移位的对象是无符号数，移位规则：逻辑左移时，高位移丢，低位添0；逻辑右移时，低位移丢，高位添0

![20190710133339831.png](https://s2.loli.net/2022/04/14/yKbU4Y9SJDBqV3p.png)

### **二、算术移位**&#x20;

算术移位的对象是有符号数，在移位的过程中符号位保持不变。

#### 对于正数

三种机器数移位后符号位均不变，左移时最高数位丢1，结果出错；右移时最低数位丢1，影响精度。

![20190717232154489.png](https://s2.loli.net/2022/04/14/179fLk6eMNjZYut.png)

#### 对于负数

对于负数，三种机器数算术移位后符号位均不变。

负数的原码左移时，高位丢1，结果出错；右移时，低位丢1，影响精度。&#x20;

负数的补码左移时，高位丢0，结果出错；右移时，低位丢1，影响精度。&#x20;

负数的反码左移时，高位丢0，结果出错；右移时，低位丢0，影响精度。

![20190717232216387.png](https://s2.loli.net/2022/04/14/Xj86F1udJhZ34S2.png)

![20190717232231894.png](https://s2.loli.net/2022/04/14/aI8zcdMYWvnBbqC.png)

#### 算术移位规则如下：

![20190710133517780.png](https://s2.loli.net/2022/04/14/niwYz1AXJPeFWpV.png)

若为双符号位，则高位符号位保持不变，低位符号位参与移动

### 三、循环移位

![20190710133734636.png](https://s2.loli.net/2022/04/14/k7N2IYjVpFloBZm.png)

（a）不带进位的循环右移：操作数循环右移位，空出的高位部分由移出的低位部分来填充。同时,CF中只保存最后一次移出的那一位的内容

（b）带进位的循环右移：操作数连同CF位循环右移，用原CF的值填补空出的位，移出的位再进入CF。

（c）不带进位的循环左移：操作数循环左移位，空出的低位部分由移出的高位部分来填充。同时,CF中只保存最后一次移出的那一位的内容

（d）带进位的循环左移：操作数连同CF位循环左移，用原CF的值填补空出的位，移出的位再进入CF。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://alma-book.gitbook.io/gitbook-cs/2.-shu-ju-de-biao-shi-yu-yun-suan/ding-dian-shu-de-yun-suan-luo-ji-yi-wei-suan-shu-yi-wei-xun-huan-yi-wei.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
