bitwise not operator

前端 未结 10 989
广开言路
广开言路 2021-01-30 16:24

Why bitwise operation (~0); prints -1 ? In binary , not 0 should be 1 . why ?

10条回答
  •  一生所求
    2021-01-30 17:01

    I think the real reason is that ~ is Two’s Complement.

    Javascript designates the character tilde, ~, for the two’s complement, even though in most programming languages tilde represents a bit toggle for the one’s complement.

提交回复
热议问题