What does (~0L) mean?

纵饮孤独 提交于 2019-12-03 12:21:41

0L is a long integer value with all the bits set to zero - that's generally the definition of 0. The ~ means to invert all the bits, which leaves you with a long integer with all the bits set to one.

In two's complement arithmetic (which is almost universal) a signed value with all bits set to one is -1.

The reason for using ~0L instead of -1L is to be clearer about the intent - it's not meant to be used as a number at all, but rather as a collection of bits.

Bitwise compliment of zero of long type.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!