业界如何将多个布尔值状态存储在一个整数中?

发布于 2024-07-25 16:29:57 字数 370 浏览 1 评论 0原文

这是一个简单的问题。

业界如何将多个布尔值状态存储在一个整数中?

SetWindowPos api 就是一个示例。

SWP_NOSIZE         DEFINE 1
SWP_NOMOVE         DEFINE 2
SWP_NOZORDER       DEFINE 4
SWP_NOREDRAW       DEFINE 8
SWP_NOACTIVATE     DEFINE 16

如果整数为 11,则 1、2 和 8(SWP_NOSIZESWP_NOMOVESWP_NOREDRAW)打开。

这种模式的流行词是什么?

Here is an easy question.

How does the industry refer to storing mulitple boolean value state in one integer?

The SetWindowPos api is an example.

SWP_NOSIZE         DEFINE 1
SWP_NOMOVE         DEFINE 2
SWP_NOZORDER       DEFINE 4
SWP_NOREDRAW       DEFINE 8
SWP_NOACTIVATE     DEFINE 16

If the integer is 11 then 1, 2 and 8 (SWP_NOSIZE, SWP_NOMOVE and SWP_NOREDRAW) are on.

What is the buzz word for this pattern?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

醉酒的小男人 2024-08-01 16:29:57

我一直将其称为“位标志”,因为它们是标志,并且每位都有一个标志。 这看起来相当标准,尽管我不能保证有多标准......

I have always called this "bit flags", since they are flags, and there is one flag per bit. This seems fairly standard, though I can't guarantee how standard...

孤单情人 2024-08-01 16:29:57

我也更喜欢“旗帜”。 该术语在许多 2 的幂进行 OR 运算的地方一致使用(举一个例子,.NET 中的 System.Reflection.BindingFlags,还有许多其他的例子)。

术语“位域”具有特定的含义,例如 C 结构中的位域 - 但在上面的示例中没有这样的结构; 程序员选择使用整数。

I prefer "flags" too. This term is used consistently in many places where powers of 2 are ORed (to give one example, System.Reflection.BindingFlags in .NET, and there are many others).

The term "bit field" has a specific meaning, e.g. bit fields in C structs - but there is no such struct in the above example; the programmer chose to use an integer instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文