What is the value of ~0 in C?

后端 未结 7 1480
暖寄归人
暖寄归人 2021-01-02 10:22

I want to get the values of INT_MIN and INT_MAX. I\'ve tried ~0 and ~0 >> 1 since the leftmost bit is a sign bit bu

7条回答
  •  萌比男神i
    2021-01-02 10:46

    On a 32bit system, 0 is 0x00000000. ~ is the bitwise not operator, which turns every 0 bit to 1 and vice versa. Therefore, ~0 (~0x00000000) gives 0xffffffff.

    This in turn is interpreted as -1 in Two's complement.

提交回复
热议问题