1

assume im dealing with CreateFileA

i have

Public Const GENERIC_ALL As Int32 = &H10000000
Public Const GENERIC_READ As Int32 = &H80000000
Public Const GENERIC_WRITE As Int32 = &H40000000
Public Const GENERIC_EXECUTE As Int32 = &H20000000

thus it means if i need read and write i would do

GENERIC_READ | GENERIC_WRITE = 0C0000000h

how would the API reverse that OR operation to know what flags it contains ?, in another words assume i got that value "0C0000000h" and i need to know what accesses it contains, what operations should i do on this number ?

my point is that if i have about 100 flags and i ORed/ANDed them then ill end up with some complicated number, how could i retrieve the flags used to compose that number ?

user3761832
  • 563
  • 2
  • 7
  • 18

1 Answers1

1

The binary AND operation can be used to test individual bits (aka flags).

For instance

bool b = (value & GENERIC_READ) != 0;

evaluates to true if GENERIC_READ was ORed into the value previously, regardless of what other flags have been combined.

If that doesn't explain it well enough, then perhaps http://en.wikipedia.org/wiki/Bitwise_operation#AND would help.

TheUndeadFish
  • 8,058
  • 1
  • 23
  • 17