What is a bit mask and when it is used??
C / C++ / MFC
2
Posts
2
Posters
0
Views
1
Watching
-
bitmasking lets you use an unsigned datatype as a collection of flags. If you use an int then you get 32 flags that you can set. To set any of the flags you would use var |= FlagToSet and to check if a flag (single bit) is set you would if (var & FlagToCheck) which will check on a bit by bit basis and return the result. If the bit(s) specified in FlagToCheck are not set in var then the result will be 0. If any of the flags are set then it will be nonzero (actual result based on which bits are set).