Explanation of Bitwise NOT Operator

前端 未结 7 1674
悲&欢浪女
悲&欢浪女 2020-11-30 07:00

Why is it that the bitwise NOT operator (~ in most languages) converts the following values like so:

-2 -> 1
-1 -> 0

7条回答
  •  半阙折子戏
    2020-11-30 07:25

    Most (all?) modern architectures use two's complement to represent signed integers. The bitwise NOT is thus the complement of the integer minus one.

提交回复
热议问题