[英]Why complement of 0 is -1?
I was learning about bitwise operators and I learnt that complement of 0 is 1 and 1 is 0. But when I tried using ~0 on IDLE, it printed -1 and when i typed ~1 it gave -2..我正在学习按位运算符,我了解到 0 的补码是 1,而 1 是 0。但是当我尝试在 IDLE 上使用 ~0 时,它会打印 -1,当我输入 ~1 时,它会给出 -2..
-1 is 0-1 => 00..00-00...01 = 1..11
So, as long as you consider some finite width (width is the size of integer or binary form you are using,4,8....),it is true that:所以,只要你考虑一些有限的宽度(宽度是 integer 的大小或你正在使用的二进制形式,4,8....),确实:
00..00 =~11..11
then, the following also be true:那么,以下情况也成立:
~0=-1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.