the use of individual bits in a byte (or a set of bytes) to represent boolean values.
Questions tagged [bitflags]
119 questions
2
votes
3 answers
Bit manipulation and Flags testing in C
Suppose I have two variables of type int, a and b, and a flag F.
#define F
int a = ;
int b = ;
What is a simple way to test that both a and b, have the flag F, or none of them has it?
To test if both of them…

Bite Bytes
- 1,455
- 8
- 24
2
votes
1 answer
C++ bitmap to hold binary flags
the problem is this: I need to create a bitmap (a series of binary flags) to hold true/false information about a bunch of objects; the number of object is not known a priori so I have to allocate enough flags at runtime, possibly during the bitmap…

fudo
- 2,254
- 4
- 22
- 44
2
votes
2 answers
What to name an array of flags?
I have a project where lots of the objects hold state by maintaining simple boolean flags. There are lots of these, so I maintain them within a uint32_t and use bit masking. There are now so many flags to keep track of, I've created an abstraction…

Chris Tonkinson
- 13,823
- 14
- 58
- 90
2
votes
1 answer
Failing to use the FlagsAttribute on an enum (Cannot resolve symbol 'HasFlag')
I have an asmx web service in c# and have recently discovered the very useful FlagsAttribute for enums. My declaration is as follows:
[Flags]
public enum eAdPriority
{
None = 0,
Gold = 1,
Silver = 2,
Homepage = 4
}
I then test the…

Jimbo
- 22,379
- 42
- 117
- 159
2
votes
4 answers
Check if Flags Enum containts all strings
I have the following flags Enum:
[Flags]
public enum RoleModels {
Master = 1 << 0,
Editor = 1 << 1,
Member = 1 << 2
}
And I have a RoleModels variable and a list of strings:
var roles1 = RoleModels.Master | RoleModels.Member;
List…

Miguel Moura
- 36,732
- 85
- 259
- 481
2
votes
4 answers
Bitflag enums in C++
Using enums for storing bitflags in C++ is a bit troublesome, since once the enum values are ORed they loose their enum-type, which causes errors without explicit casting.
The accepted answer for this question suggests overloading the |…

sold
- 2,041
- 5
- 25
- 32
2
votes
5 answers
Determine Position of Most Signifiacntly Set Bit in a Byte
I have a byte I am using to store bit flags. I need to compute the position of the most significant set bit in the byte.
Example Byte: 00101101 => 6 is the position of the most significant set bit
Compact Hex Mapping:
[0x00] => 0x00
[0x01] …

recursion.ninja
- 5,377
- 7
- 46
- 78
2
votes
0 answers
PHP/MySQL Field/Column Bit-Flags: UNIQUE_KEY_FLAG vs. UNIQUE_FLAG
In PHP, when extracting bit-flags from MySQL columns/fields, I see (from other SO answers):
UNIQUE_KEY_FLAG = 4
UNIQUE_FLAG = 65536
I'm wondering what the difference is between these two bit-flags?
And why do the lists that I do find show both…

Keith DC
- 661
- 1
- 9
- 24
1
vote
2 answers
Is it possible to check for exactly n flags are set for an enum in C++ std::unordered_map key?
I am setting up an unordered_map, in which the key is an enum of Direction defined as:
enum Direction : uint16_t {
North = 1 << 0,
East = 1 << 2,
South = 1 << 3,
West = 1 << 4,
None = 1 << 5,
};
The goal is to check if at least…

Ian
- 65
- 1
- 8
1
vote
1 answer
Deserializing a bitflag enum in C# with Unity
I have a unity project. Using the stock json tools at my disposal, i'm trying to deserialize an enum that uses bit flags (ie something like)
[Flags]
enum Terrain
{
NORMAL = 0,
FOREST = 1,
SWAMP = 2,
CAVE = 4
}
In json it's something like…

nuk
- 39
- 6
1
vote
2 answers
Can I decompose a Python Flag enum into its fundamental parts?
I have an enum that represents the directions you're allowed to move for a given cell in a maze:
class Direction(Flag):
NORTH = 1
EAST = 2
SOUTH = 4
WEST = 8
NE = NORTH | EAST
NW = NORTH | WEST
...etc
NESW = NORTH |…

codebreaker
- 763
- 1
- 7
- 24
1
vote
1 answer
Why cout.flags() & std::ios_base::right prints 0 even though by default the output is right aligned
I am learning C++'s iostream. In particular, I have learnt that by default the output of cout is right aligned. For example, if I write:
#include
#include
int main()
{
std::cout << setw(10) << "abb" ; //this is guaranteed to…

Alex
- 318
- 1
- 14
1
vote
1 answer
Groupby and Count Flags as indexes in Pandas
I have a dataframe which has flags 0/1 for multiple products along with accounts and which zipcode they belong to. My Goal is to count the 1's in columns which have been created as flags.
Zip acc A B
32123 214124 1 0
32123…

m2rik
- 135
- 7
1
vote
5 answers
searching bit-field templates (codebooks)
I've got a bunch of 8-bit values in a codebook (about 200 of them).
My program will be generating an 8-bit value in response to input, and I need to find all (or even the first is helpful) of the matches in the codebook that have the same bits set.…

akevan
- 691
- 1
- 9
- 21
1
vote
1 answer
How to store Processor Status flags' values with corresponding enum for 6502
I'm working on 6502 emulator in C++ as a part of my thesis. It has 6 registers, most of them just hold values but there's one special - Processor Status. It's 8 bit wide and each bit means a different flag. The best choice for me seemed to make it…

Sebastian Kucharzyk
- 85
- 7