the use of individual bits in a byte (or a set of bytes) to represent boolean values.
Questions tagged [bitflags]
119 questions
3
votes
3 answers
Bitwise flag issue
I have a series of bit flags that order something like {none=0x00, puppies=0x01, kittens=0x02, cute=0x04, funny=0x08, scary=0x10} and so forth.
Whenever a user does a search, I just |= each of the flags that they wish, e.g. if a user wants…
user499054
3
votes
1 answer
set a flag in int variable from different context on bare metal controller
For avr 8 bit micro controller a single bit ( flag ) must be set or cleared in some 8 bit integer variable. This set/clear function can be called from normal context ( main ) and also from interrupt handler ( Isr() ). As this, the variable must be…

Klaus
- 24,205
- 7
- 58
- 113
3
votes
3 answers
How to use bitwise flags in Python
from enum import Enum
class InputTypes(Enum):
"""
Flags to represent the different kinds of input we
are acting on from the user
"""
KEYBOARD = 0b00000001,
MOUSE_BUTTONS = 0b00000010,
MOUSE_MOVE = 0b00000100,
ALL =…

Christopher Pisz
- 3,757
- 4
- 29
- 65
3
votes
1 answer
Detecting at least one bit is set in collection of bitfields
In my program I have a C bit-field structure as:
typedef struct
{
char a:1;
char b:1;
char c:1;
char d:1;
}_OpModes;
_OpModes Operation;
Now I want to check at least one of the flags is set in the above structure, If so do some…

Nagendra Babu
- 69
- 7
3
votes
2 answers
Handling PHP Bit Flags
I have a PHP class with a method that prints out an instance into a table row. Sometimes I want a row to be printed out without the name at the start, sometimes I want all the row items to be printed, and so on.
I have decided to use bit flags in…

worldofjr
- 3,868
- 8
- 37
- 49
3
votes
2 answers
How to calculate Bit Flag in javascript?
im writing a free tool for SEO... implementing an api from seomoz and the flags look like this
URL Metric,Bit Flag
Title,1
URL,4
Subdomain,8
Root Domain,16
External Links,32
Links,2048
mozRank,16384
mozTrust,131072
these are just a few but i dont…

Carter Cole
- 918
- 9
- 16
3
votes
2 answers
NS_OPTIONS Bitmask Autogeneration
I have a large enum (for the sake of transparency 63 values), and I am now creating a NS_Options bitflag based on that enum. Is there a way that I can write this so that it will be flexible?
The main concerns I have with hardcoding it are:
If I…

paulrehkugler
- 3,241
- 24
- 45
3
votes
3 answers
Creating bitflag variables with large amounts of flags or how to create large bit-width numbers
Lets say I have an enum with bitflag options larger than the amount of bits in a standard data type:
enum flag_t {
FLAG_1 = 0x1,
FLAG_2 = 0x2,
...
FLAG_130 = 0x400000000000000000000000000000000,
};
This is impossible for several reasons. Enums are…

J V
- 11,402
- 10
- 52
- 72
2
votes
2 answers
Binary flags for functions in php
Good day everyone.
I'm trying to figure out a way to use multiple flags for a function, without increasing number of arguments.
For example to use it like that some_func(flag1|flag2|flag3);
For now I did it like that
define('flag1',…

NewProger
- 2,945
- 9
- 40
- 58
2
votes
5 answers
Extend Enum with flag methods?
I have found good examples on how to create extension methods to read out single values from bitwise enums. But now that C# 4 has added the HasFlag method they are really not needed.
What I think would be really helpful though is an extension to…

Jakob Lithner
- 4,225
- 6
- 38
- 59
2
votes
9 answers
How to use a bitflag on an unsigned int in order to store an additional bool value in it
I use unsigned ints representing a bunch of airplanes in a game. Each plane has two states, flying and grounded. I would like to store this state together with the planes number. What is the "best" way to achieve that? I could use std::maps with the…

Lumpi
- 2,697
- 5
- 38
- 47
2
votes
3 answers
Is there any reason to use enum params over bit flags in c#?
Lets say, for example, I have two implementations, one with bit flags and one with simple enum:
1) bit flags
[Flags]
public enum LettersBitFlags
{
A = 1,
B = 2,
C = 4,
D = 8
}
public static bool IsLetterBBitFlags(LettersBitFlags…

helgez
- 157
- 1
- 7
2
votes
7 answers
How to pick bitflag values?
I have a set of options, some orthogonal (can be combined in any combination), some exclusive (only one from the set is allowed), and need to pick a set of enum values so that they can be combined with bit-wise or and extracted with bit-wise and. I…

BCS
- 75,627
- 68
- 187
- 294
2
votes
2 answers
Struct with mixed bitflag and normal members
I'm trying to recreate a C struct with mixed bitfield members and "normal" members in Rust for FFI.
I've read that the bitflags crate would be the one to go with, unfortunately I find the documentation lacking on the regards how the syntax actually…

ljrk
- 751
- 1
- 5
- 21
2
votes
1 answer
Why does compiling bitflags 1.0 produce an "expected ident, found #" error?
When I try to build a project in Rust with bitflags v1.0.1 in macOS Sierra 10.12.6 the code fails with the following error:
Compiling bitflags v1.0.1
error: expected ident, found #
-->…

Kent Marete
- 117
- 1
- 6