Questions tagged [bitflags]

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

119 questions
1
vote
1 answer

Delphi Setting bit Flags

a little out of my depth here. I am using a component that has some Flags in the Object Inspector ... FCOPY Flags flShowProgress flConfirmation I need to change flShowProgess depending on the size of a file being copied. if…
1
vote
0 answers

Grouping bits in a union or using bitarray

I need to implement grouped bits in the following code or use the bitarray implementation to achive this: e.g: The bits logout,Idle should belong to a group say "close", if any of the bits logout or Idle are 1 then I should be able to read the …
stackit
  • 3,036
  • 9
  • 34
  • 62
1
vote
1 answer

How to clear the state bits in an iostream object in C++?

I'm trying to learn C++ from an older edition of the Primer, and tried to execute some of their code relating to iostream objects, which gave me some trouble: #include #include using namespace std; int main(int argc, char…
1
vote
6 answers

#defined bitflags and enums - peaceful coexistence in "c"

I have just discovered the joy of bitflags. I have several questions related to "best-practices" regarding the use of bitflags in C. I learned everything from various examples I found on the web but still have questions. In order to save space, I am…
user151410
  • 776
  • 9
  • 22
1
vote
3 answers

Efficiently Check Bitflag Invariant (possible bit-twiddle)

I have a byte I am using to store bit flags. I have 8 flags (one for each bit) that can be divided into 4 pairings of 2 flags which are mutually exclusive. I have arranged the bit flags in the following fashion: ABCDEFGH 10011000 Flag A cannot be…
recursion.ninja
  • 5,377
  • 7
  • 46
  • 78
1
vote
1 answer

Is there an intuitive way of checking for flags and states?

Couldnt find a relevant answer to my case so i will try explaining my situation: I have the following code: enum Flags { OnlySpaces = 1 << 0, valComment = 1 << 1, valCommentBlock = 1 << 2, valLabelName = 1 << 3, …
RaptorX
  • 331
  • 1
  • 9
  • 19
1
vote
1 answer

How do I read bit flags mixed with data?

I've never wandered into reading binary data before. I'm trying to learn now, and make a simple application to read the header data from a FLAC file and display the information in human readable format. As a first, given that the first bit of data…
Mirrana
  • 1,601
  • 6
  • 28
  • 66
0
votes
1 answer

Determining signed overflow (x86 Overflow / Auxilliary Flags)

First of all: I really tried to find a matching answer for this, but I just wasn't successful. I am currently working on a little 8086 emulator. What I haven't still figured out is how the Overflow and Auxilliary flags are calculated best for…
muffel
  • 7,004
  • 8
  • 57
  • 98
0
votes
1 answer

Checking for multiple bitflags - binary comparison in [PHP]

Checking for multiple flags. I just want to know if there is another way to check for multiple flags, different from &&? class DemoClass { public const MY_FLAG1 = 0b1; // 0001 // 1 public const MY_FLAG2 = 0b10; // 0010 // 2 public…
DevWL
  • 17,345
  • 6
  • 90
  • 86
0
votes
1 answer

Determine if flag value is valid

I have a Number value I'm sending to an API and I want to soft check on the front end if the value is a valid "flag" before shipping it off. So far as I can figure, a flag is any number where the bit value starts with a 1 and then is followed by…
Randy Hall
  • 7,716
  • 16
  • 73
  • 151
0
votes
3 answers

How to format flags in c?

Assume that there are flag definitions such as: SHF_WRITE 0x1 SHF_ALLOC 0x2 SHF_EXECINSTR 0x4 SHF_MASKPROC 0xf0000000 Given a flag, I need to output SHF_WRITE|SHF_ALLOC if the bits 0x1 and 0x2 is on. How to do the trick in C?
R__
  • 1,441
  • 5
  • 16
  • 22
0
votes
1 answer

/usr/bin/link: missing operand after ‘\377\376"’ when compiling bitflags

Following Phillip Opperman's Blog OS, I have been trying to use the bitflags and x86_64 rust crates. The latest x86_64 crate release has bitflags 1.0.4 as a dependency which makes sense. However, I have been completely unable to compile bitflags…
Ben k
  • 15
  • 3
0
votes
1 answer

Bit flag to enum not getting the right results

In the below code, i'm trying to convert int bit flags to enum, but I'm not getting the right results. Enum Flags enum class State { NONE = 0, FORWARD =4, BACKWARD =5, } Bit Flag and conversion infix fun Int.withFlag(flag: Int) =…
0
votes
1 answer

Is there an easier way to parse an int to a generic Flags enum?

I've got a generic function to parse an object into a generic Enum. However, I'm running into an issue when trying to safely parse an int into a [Flags] Enum. Directly using Enum.ToObject() works to parse valid combinations, but will just return…
M. McCrary
  • 35
  • 3
0
votes
1 answer

Check if set of bitflags include atleast one flag of other bitflags

I'm programming an event system, where every listener listens to one, multiple or all channels (GameEventChannel enum) and and event can be raised only for one, multiple or all channels (GameEventChannels). What i have right now…