ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I do a bit mask?

Solved!
Go to solution
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?
0 Kudos
Message 1 of 7
(16,078 Views)

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
Message 2 of 7
(16,071 Views)

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
Message 3 of 7
(16,070 Views)

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!
Message 4 of 7
(16,054 Views)
Solution
Accepted by garya505
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

Message 5 of 7
(16,028 Views)

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.  🙂

 

Message 6 of 7
(16,013 Views)

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. 

0 Kudos
Message 7 of 7
(15,986 Views)