Jump to content
  • Advertisement

Archived

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

FrancoisSoft

Extracting Data using Bitwise Operators

This topic is 5432 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
just use an ''and'' operator

??=&

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!