What does ~0 do?

前端 未结 4 1986
有刺的猬
有刺的猬 2020-12-11 08:13

Does ~0 mean its flipping 000000000 to 1111111111?

printf(\"Check: %i\", ~0);

The printf results to -1, which is why I am confused. <

4条回答
  •  鱼传尺愫
    2020-12-11 08:56

    It is due to the mathematical operation "two's complement". A nice video tutorial of two's complement can be found on youtube. Here's one of them :)

    youtube link

提交回复
热议问题