> For the complete documentation index, see [llms.txt](https://r24zeng.gitbook.io/leetcode-notebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://r24zeng.gitbook.io/leetcode-notebook/bu-chong-6180-dao/201.-bitwise-and-of-numbers-range.md).

# 201. Bitwise AND of Numbers Range

\# Medium

{% hint style="info" %}
Key idea: find the common bits from left to right, it's the result

So compare m and n from removing most right bit until they are equal.
{% endhint %}

```python
class Solution:
    def rangeBitwiseAnd(self, m: int, n: int) -> int:
        for i in range(32):
            if m >> i == n >> i:
                res = m >> i
                return res << i
```
