cancel
Showing results for 
Search instead for 
Did you mean: 

How can I do a bit mask?

SOLVED
garya505
Member
Solved!

How can I do a bit mask?

How can I do a bit mask in LabVIEW?  For example, what the easiest way to see if bit 3 is set in a 32-bit unsigned int?
6 REPLIES 6
dan_u
Active Participant

Re: How can I do a bit mask?

AND the U32 with another U32 with the 3rd bit set to 1 (easy to do in binary formatting).

To set a bit, use the OR operator.

Boolean operators work very nice with integer numbers.

 

Message Edited by dan_u on 03-12-2010 01:06 AM
Yamaeda
Proven Zealot

Re: How can I do a bit mask?

your int AND 4 (or change visual option of the '4' to binary and write '100')


Then either compare to 0, 4 or >0.

/Y
G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
jyang72211
Active Participant

Re: How can I do a bit mask?

Given: X is the input for bit 3 testing

 

1. X AND 8 = y (notice that at is 00000000000000000000000000001000 binary in decimal)

2. Convert y to a boolean array = z

3. Or all element in array(z) = result

 

If result is true, bit 3 is set.  If not, bit 3 is clear.

 

Yik

 

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
Highlighted
jcarmody
Trusted Enthusiast
Solution

Re: How can I do a bit mask?

Message contains an image
As already said, AND.

 Example_VI.png
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Ray.R
Knight of NI

Re: How can I do a bit mask?

Well explained Jim.

 

If you do a bit mask and the bit(s) you are looking for is set, then it does not matter what the answer is, it will not be zero.  So result != 0 means the bit was set.  Smiley Happy

 

garya505
Member

Re: How can I do a bit mask?

Thanks to all for the great answers!  My first reading of the LV Help for AND led me to think it was only boolean, not bitwise.