How do I check if bitmask contains a bit?
source link: https://www.codesd.com/item/how-do-i-check-if-bitmask-contains-a-bit.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How do I check if bitmask contains a bit?
I don't quite understand this whole bitmask concept.
Let's say I have a mask:
var bitMask = 8 | 524288;
I undestand that this is how I would combine 8
and 524288
, and get 524296
.
BUT, how do I go the other way? How do I check my bitmask, to see if it contains 8
and/or 524288
?
To make it a bit more complex, let's say the bitmask I have is 18358536
and I need to check if 8
and 524288
are in that bitmask. How on earth would I do that?
if (8 & bitmask == 8 ) {
}
will check if the bitmask contains 8.
more complex
int mask = 8 | 12345;
if (mask & bitmask == mask) {
//true if, and only if, bitmask contains 8 | 12345
}
if (mask & bitmask != 0) {
//true if bitmask contains 8 or 12345 or (8 | 12345)
}
may be interested by enum and more particularly FlagsAttibute.
Related Articles
How do I check if text1 contains text2 using vb6?
Bitwise - How do I check if a binary number contains another?
How do I check an input string does it contain an address or not?
How do I check whether the value in the active cell contains a letter or not?
How do I check if the controls in a usercontrol contain a value?
Using Spring's mockMvc, how do I check if the returned data contains part of a string?
How do I check if the file name contains a substring in JavaScript?
How to check a string contains another string
How do I check if a variable contains a specific text
How to check the array contains different values or same values in Jquery
How do I check if the identifier contains several words?
How do I check if the snapshot contains a specific value in Firebase?
How do I check if an NSMutableArray contains an object containing some text?
How do I check if a string contains Å, Ä or Ö characters in java servlet?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK