业界如何将多个布尔值状态存储在一个整数中?
这是一个简单的问题。
业界如何将多个布尔值状态存储在一个整数中?
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_NOSIZE
、SWP_NOMOVE
和 SWP_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
位字段
a bit field
我一直将其称为“位标志”,因为它们是标志,并且每位都有一个标志。 这看起来相当标准,尽管我不能保证有多标准......
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...
位集或位数组
bitset or bit array
我也更喜欢“旗帜”。 该术语在许多 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.