Questions tagged [bitflags]

the use of individual bits in a byte (or a set of bytes) to represent boolean values.

119 questions
6
votes
3 answers

What's the optimal way to store binary flags / boolean values in each database engine?

I've seen some possible approaches (in some database engines some of them are synonyms): TINYINT(1) BOOL BIT(1) ENUM(0,1) CHAR(0) NULL All major database engine supported by PHP should be noted, but just as a refference it'll be even better if…
xun
  • 607
  • 2
  • 7
  • 10
6
votes
2 answers

Decoding a bitmask from a value in C#

I am trying to decode a bitmask [Flags] public enum Amenities { BusinessCenter = 1, FitnessCenter = 2, HotTub = 4, InternetAccess = 8, KidsActivities = 16, Kitchen = 32, PetsAllowed = 64, Pool = 128, Restaurant =…
239revilo
  • 101
  • 2
  • 10
5
votes
1 answer

What is the purpose of the flags struct in iOS?

struct { unsigned resizesCellWidths:1; unsigned numColumns:6; unsigned separatorStyle:3; unsigned allowsSelection:1; unsigned backgroundViewExtendsUp:1; unsigned backgroundViewExtendsDown:1; unsigned…
xeonarno
  • 426
  • 6
  • 17
5
votes
1 answer

How to make sense of O_RDONLY = 0?

I am dealing with file status flags. Among test I performed, I found #include #include "fcntl.h" int main() { const int flag = O_RDONLY; printf( "*** Flag O_RDONLY = %5d\n", flag); return 0; } produces this output *** Flag…
5
votes
5 answers

Is there a pattern or a method in C# to check if an (int 1,2,4,8,...) option is true or false

I like to write enum or integer to pass option to my methods. Is there a pattern or a method in C# to check if an (int 1,2,4,8,...) option is true or false. I think it should easily be possible via binary functions. class Program { public enum…
Bastien Vandamme
  • 17,659
  • 30
  • 118
  • 200
5
votes
5 answers

How to implement flags with the options true,false,default and toggle in C++?

I'm currently trying to come up with a clever way of implementing flags that include the states "default" and (optional) "toggle" in addition to the usual "true" and "false". The general problem with flags is, that one has a function and wants to…
Anedar
  • 4,235
  • 1
  • 23
  • 41
5
votes
2 answers

C++ Bitflaged enum to string

I'm trying to do what Intellisense does in visual studio when you hover over a bitwise-enum (or however it's called) variable (while debugging), by taking an enum and converting it to string. for example: #include enum Color { White…
ZivS
  • 2,094
  • 2
  • 27
  • 48
5
votes
4 answers

Is there a name for the technique of using base-2 numbers to encode a list of unique options?

I am writing a couple of functions that encode and decode a list of options into a Long so they can easily be passed around the application, you know this kind of thing: 1 - Apple 2 - Orange 4 - Banana 8 - Plum etc. In this case the number 11 would…
Lunatik
  • 3,838
  • 6
  • 37
  • 52
5
votes
2 answers

What data structure for an array of bit flags?

I'm porting some imperative code to Haskell. My goal is to analyze an executable, therefore each byte of the text section gets assigned a number of flags, which would all fit in a byte (6 bits to be precise). In a language like C, I would just…
Sebastian Graf
  • 3,602
  • 3
  • 27
  • 38
4
votes
3 answers

Testing bitmask when stored as integer and available as string

I have a bitmask (really a 'flagmask') of integer values (1, 2, 4, 8, 16 etc.) which apply to a field and I need to store this in a (text) log file. What I effectively store is something like "x=296" which indicates that for field "x", flags 256, 32…
roryhewitt
  • 4,097
  • 3
  • 27
  • 33
4
votes
1 answer

C - Using enum for bit flags - warning: enumerated type mixed with another type

I'm passing enumeration constants as bit-flags to a function that expects the enumeration type as input, like this: // Enumeration type typedef enum { LED_RED = (1 << 0), LED_GREEN = (1 << 1), LED_YELLOW = (1 <<…
Eliahu Aaron
  • 4,103
  • 5
  • 27
  • 37
4
votes
4 answers

Parsing enum flags from comma-separated list or integer

I have an XML that contains several flags, some of them are unsigned 32-bit integers and others are unsigned 64-bit integers. Some of them are written in a comma-separated list and others are in hex style. See this…
richi3f
  • 47
  • 1
  • 6
3
votes
2 answers

Conditional statement against _WinAPI_EnumDisplayDevices() -returned bitflag

_WinAPI_EnumDisplayDevices() reports 3 additional virtual monitors I don't need. So I've created an If statement where if specific flags come about (such as 1, 2, 3, 35, or 33), it only returns those monitors. However, it bugs me how long my…
Anthony Miller
  • 15,101
  • 28
  • 69
  • 98
3
votes
1 answer

Why are only 128 characters encoded to one byte in UTF-8 and not 256 characters?

I'm trying to grasp UTF-8 encoding. The encoding of code points can range from 1 to 4 bytes. There are only 128 characters which encode to one byte. But since a byte has 8 bits it could encode 256(=2⁸) characters. Therefore, why are only 128…
Piet Pro
  • 33
  • 3
3
votes
2 answers

How to check if a bit is set in PowerApps?

How do I check if a particular bit is set on an integer value within a PowerApp? There doesn’t seem to be a built-in operator or function for bit manipulation. As I do need this for quite few operations, using an external / Custom Connector is…
muffel
  • 7,004
  • 8
  • 57
  • 98