> For the complete documentation index, see [llms.txt](https://cai-sen-se.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cai-sen-se.gitbook.io/leetcode/1001-2000/1009.-shi-jin-zhi-zheng-shu-de-fan-ma.md).

# 1009. 十进制整数的反码

<https://leetcode-cn.com/problems/complement-of-base-10-integer/>

同476. 数字的补数

## 解法一：

```python
class Solution:
    def bitwiseComplement(self, n: int) -> int:
        height = 0
        for i in range(31):
            if n >= 1 << i:
                height = i
        mask = (1 << (height+1)) - 1
        return n ^ mask
```
