Explanation of Bitwise NOT Operator

前端 未结 7 1676
悲&欢浪女
悲&欢浪女 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:15

    This is due to how negative numbers are represented as bits. For this most commonly Two's Complements are used.

    -2 happens to be 1111110 in this notation, which negated is 1

提交回复
热议问题