Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在学习按位运算符,我了解到 0 的补码是 1,而 1 是 0。但是当我尝试在 IDLE 上使用 ~0 时,它会打印 -1,当我输入 ~1 时,它会给出 -2..
-1 is 0-1 => 00..00-00...01 = 1..11
所以,只要你考虑一些有限的宽度(宽度是你正在使用的整数或二进制形式的大小,4,8 ....),这是真的:
00..00 =~11..11
那么,以下情况也成立:
~0=-1