views:

122

answers:

4

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?

+11  A: 

a bit field

Pete Kirkham
+1 Nothing more, nothing less.
Magnus Skog
Except not hyphenated.
Nosredna
+7  A: 

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...

brone
This is my preferred for the general case. "Bitfield" should only be used when the bits fit in a machine word (otherwise you have a "bit array").
Nosredna
I prefer "flags" too
azheglov
fields is better because sometimes you pair up bits to hold 3-state and 4-state data (and larger combinations).
jmucchiello
+3  A: 

bitset or bit array

dfa
+1  A: 

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.

azheglov