> For the complete documentation index, see [llms.txt](https://docs.1l.lol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.1l.lol/basics/complement.md).

# 数学与补码/反码

### 幂的运算

* 任何非零数的 0 次方等于 1：`a^0 = 1 (a ≠ 0)`
* `0^0` 无意义
* 同底数幂相乘：`a^m × a^n = a^(m+n)`

### 原码、反码、补码

计算机中**整数用补码存储**。以 8 位为例：

| 编码 | 正数         | 负数           |
| -- | ---------- | ------------ |
| 原码 | 符号位 0 + 数值 | 符号位 1 + 数值   |
| 反码 | 与原码相同      | 符号位不变，其余各位取反 |
| 补码 | 与原码相同      | 反码 + 1       |

```
+5 原码/反码/补码：0000 0101
-5 原码：1000 0101
-5 反码：1111 1010
-5 补码：1111 1011
```

### 8 位有符号整数的范围

**-128 \~ 127**（不是 -127）。

* 最大值 `0111 1111 = 127`
* 最小值 `1000 0000 = -128`（补码中多出一个数用于表示 -128）

### 为什么用补码

* 把减法变成加法：`a - b = a + (-b)`，硬件只需加法器
* 0 只有一种表示，避免 +0 / -0 的歧义

### 相关

更详细的编码与进制见「计算机基础」分组的《数据编码（原码、反码、补码）》。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.1l.lol/basics/complement.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
