What does (~0L) mean?

强颜欢笑 提交于 2019-12-04 17:23:34

问题


I'm doing some X11 ctypes coding, I don't know C but need some help understanding this.

In the C code below (might be C++ im not sure) we see (~0L) what does that mean? In Javascript and Python ~0 means -1.

812   int result = GetProperty(window, property_name,
813                            (~0L), // (all of them)
814                            &type, &format, &num_items, &properties);

Thanks


回答1:


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.




回答2:


Bitwise compliment of zero of long type.



来源:https://stackoverflow.com/questions/27596116/what-does-0l-mean

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