Archived

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

FrancoisSoft

Extracting Data using Bitwise Operators

Recommended Posts

FrancoisSoft    99
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 this post


Link to post
Share on other sites
tortoise    122
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.

Share this post


Link to post
Share on other sites