是什么(〜0L)是什么意思? [英] What does (~0L) mean?

查看:1059
本文介绍了是什么(〜0L)是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一些X11 ctypes的编码,我不知道C,但需要一些帮助理解这一点。

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

在下面的C code(可能是C ++林不知道)我们看到(〜0L)这是什么意思?在Javascript和Python 0〜办法 1

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);

感谢

推荐答案

0L 是一个的整数值所有位设置为零 - 这通常是的定义0 。在表示反转所有位,这让您与设置为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.

在补运算(这几乎是普遍的)一个符号值均设置为1所有位为 1

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

之所以使用〜0L 而不是 -1L 是要对意图更加清晰 - 它并不意味着被用作一个数在所有的,而是作为位的集合

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.

这篇关于是什么(〜0L)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆