# 201. 数字范围按位与

<https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/>

## 解法一：

思路是找出m和n**相同**和**不同**的部分。相同部分与之后结果不变，不同部分与结果为0。每次n，m左移一位，直到n==m，用move来统计移动的位数（不同的位数）。最后用m\*move还原（即给m补0）。

```python
class Solution:
    def rangeBitwiseAnd(self, m: int, n: int) -> int:
        #边界，不加也行，不过慢
        if m == 0:
            return 0
        move = 1
        while n != m:
            n >>= 1
            m >>= 1
            move <<= 1
        return m * move
```


---

# 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://cai-sen-se.gitbook.io/leetcode/201-400/201.-shu-zi-fan-wei-an-wei-yu.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.
