2

How do I check if bitmask contains a bit?

 3 years ago
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.
neoserver,ios ssh client

How do I check if bitmask contains a bit?

advertisements

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?

How to check if text1 contains text2 using vb6 ? Dim text1 as string Dim text2 as string text1 = "hello world I am Anas" text2 = "Anas" if (check if text2 is in text1) 'the result should be true or false You can use InStr function like

Bitwise - How do I check if a binary number contains another?

A = 110000000 - 384 Blue+Red B = 011000010 - 194 Green+Black+Red A & B = C = 010000000 - 128 Red How can I check if B contains all the bits in A and perhaps others? In the case above I would like to get "false". I'm using XCode & objecti

How do I check an input string does it contain an address or not?

We want to identify the address fields from a document. For Identifying the address fields we converted the document to OCR files using Tesseract. From the tesseract output we want to check a string contains the address field or not . Which is the ri

How do I check whether the value in the active cell contains a letter or not?

For example cell "A1" is linked to cell "B1", so in formula bar for cell "A1" we have: =B1 How can I check whether value in cell "A1" contains letter B? I tried the following: Dim Criteria_3 As Boolean Dim Value As

How do I check if the controls in a usercontrol contain a value?

How do I check whether the controls in a usercontrol contain any value? I have created a usercontrol called ctlCustomerAddress and I want to create an address record in the database if only I have the values in the textboxes.There are number of ways

Using Spring's mockMvc, how do I check if the returned data contains part of a string?

I'm using Spring 3.2.11.RELEASE and JUnit 4.11. Using the Spring mockMvc framework, how do I check if a method returning JSON data contains a particular JSON element? I have mockMvc.perform(get("/api/users/" + id)) .andExpect(status().isOk()) .a

How do I check if the file name contains a substring in JavaScript?

This question already has an answer here: How to check whether a string contains a substring in JavaScript? 48 answers I have a folder on the hard drive with files named myfileone_163637 myfiletwo_14153535 myfilethree_3739284 The numbers at the end o

How to check a string contains another string

This question already has an answer here: How can I check if a string exists in another string 7 answers I i have string of numbers separated by commas ,How to check if another string contained in that string . For example : If i have a string : 67,7

How do I check if a variable contains a specific text

how do I check if a variable in php contains text? eg: if ($cn contains 'excel') { ... } I've currently got the following that works but it is clumsy for if a course name changes then it will not work anymore. if (strpos($cn,'MS Excel 2003/07 (Intro)

How to check the array contains different values ​​or same values ​​in Jquery

This question already has an answer here: How to know if two arrays have the same values 10 answers An array can contains multiple values. I want to check whether all the values are same or different. Example var a = [2, 4, 7, 2, 8]; // all values ar

How do I check if the identifier contains several words?

I have a div: <div id="picture_contents_12356_title"></div> The '12356' is a unique id that is auto-generated and I need to have it there. How can I create a jQuery selector for an id that has "picture_contents" AND "t

How do I check if the snapshot contains a specific value in Firebase?

When I run this code I get an error that says this: Terminating app due to uncaught exception 'InvalidPathValidation', reason: '(hasChild:) Must be a non-empty string and not contain '.' '#' '$' '[' or ']'' My problem is how do I check if my snapshot

How do I check if an NSMutableArray contains an object containing some text?

How can I check if an NSMutableArray contains an object which contains certain text? Then, if there is one piece of text which has been found, it will replace it with another bit of text. ThanksSomething like this should work: @interface NSMutableArr

How do I check if a string contains Å, Ä or Ö characters in java servlet?

I am using java servlets. In my database some strings has characters Å, Ä and Ö. When i check those strings contains these special characters then its always false. How can i check if a string contains these special characters. I am using Eclipse. Th

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK