#### Archived

This topic is now archived and is closed to further replies.

# Extracting Data using Bitwise Operators

## Recommended Posts

Ok, here''s the scenario: There is this data that has been passed into a DWORD variable. Let''s say...  DWORD Attributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY; // Let''s say that I want to test is the attribute is a // directory (FILE_ATTRIBUTE_DIRECTORY). What do I do? if (Attributes ?? FILE_ATTRIBUTE_DIRECTORY) DoStuff();  See where the question marks are? I''m stuck. What do I put here? Hey, don''t forget to visit my page... by clicking here!

##### Share on other sites
just use an ''and'' operator

??=&

##### Share on other sites
if(Attributes & FILE_ATTRIBUTE_DIRECTORY) {
...
}

''and'' means to take the bits of the first number, the bits of the second number, then form a new number that only has a bit set if that bit was found in both numbers. So if Attributes has the FILE_ATTRIBUTE_DIRECTORY bit set, then the above result will be nonzero (because the result will have at least one bit set), ie positive.

• ### Forum Statistics

• Total Topics
628308
• Total Posts
2981973

• 9
• 13
• 11
• 12
• 11