按位NOT运算符的说明 [英] Explanation of Bitwise NOT Operator
本文介绍了按位NOT运算符的说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么按位NOT运算符(在大多数语言中为〜
)会转换以下值:
Why is it that the bitwise NOT operator (~
in most languages) converts the following values like so:
-2->1
-1->0
0->-1
1->-2
-2
不能转换为 2
, 1
不能转换为 -1
,等等?
Shouldn't -2
convert to 2
, 1
convert to -1
, etc.?
推荐答案
请参见二进制补码在许多语言中为负整数.如您所见,-2由 1111110
表示;如果将所有这些位取反,则得到 0000001
,即值为1.
See two's complement for the representation of negative integers in many languages. As you can see, -2 is represented by 1111110
; if you invert all those bits you get 0000001
, i.e. a value of 1.
这篇关于按位NOT运算符的说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文