Showing results for 
Search instead for 
Did you mean: 

Boolean logic : Enabling & Disabling Bit

Go to solution



****** I know how to enable a bit (set bit high) in LabVIEW.  ********

For example, let say I have 101, and I want to enable the middle bit. 

To enable the middle bit I would use the OR operation.  101 OR with 10 which would produce 111. I can do this in LabVIEW.

Check the attachments. 


*******Can someone tell me how to disable a bit (set bit low) using LabVIEW?  ******

Now let says I have 111, and I want to disable the middle bit in LabVIEW?   I know I should just use And operation.

111 AND with 101 will produce 101.   I am not sure how to do this in LabVIEW. PLEASE HELP.

0 Kudos
Message 1 of 22
I don't understand what you are trying to do. What is wrong with just a numeric set for binary display or a Boolean array?
0 Kudos
Message 2 of 22

I want to set certain bits to zero. Bit i specific  



if i had 7 (decimal number ) which mean i have 111. How do i change the second bit to zero?  I would use AND operation. So 111 AND 101 will produce 101. 


How can i do this in labview ? 

0 Kudos
Message 3 of 22
Accepted by topic author sticyfinger

You do almost exactly the same thing as you did for enabling the bit. After the 2^n function, negate the result (using the boolean NOT function), which will give you all bits set to 1 except the one you want. Then you can use AND to set just that bit to 0.

0 Kudos
Message 4 of 22

Logical operators accept integers and operate bitwise on them


For more info see this shipping example


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 22

I'm much better at visualizing flipping bits, so I convert to an array of booleans, flip the appropriate bit and convert it back to a number.  I know it's not efficient, but for me I'm a lot less error-prone if I do it that way.  I must have some kind of mental block.

(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 22
I still don't understand the need for such complexity. If you have a numeric control, to set bit 1 to zero, you simply enter 101 into the control when it is set for binary display. Or as I mentioned, use Boolean array.
0 Kudos
Message 7 of 22

@Dennis_Knutson wrote:
I still don't understand the need for such complexity. If you have a numeric control, to set bit 1 to zero, you simply enter 101 into the control when it is set for binary display. Or as I mentioned, use Boolean array.

If you look at the attached JPG, the question seems to be how to set or clear an arbitrary bit. The poster would like to enter a bit position, and then either set or clear it. The code is almost there (well, the JPG image, anyway - I can't open the VI due to LabVIEW version mismatch).

0 Kudos
Message 8 of 22


@ Dennis,


Background info:

I will not have a numerical control in my final program. I just used that VI, as a demo, to show what I was trying to do. I did not want to make it more complex than it needed to be.  If you must know, the numerical control used in the attached demo code will be an array of bytes for the final version of the code.  Each bit will represent commands.  I just want to change one bit at a time and not worry about the rest of the bits.




I think I have solved it with the attached VI.  I do not like how I am disabling the bit (setting the bit to zero). That why I asked for him. It seems like a lot of work and less efficient to "convert to Boolean array", "negate", then "convert Boolean array to number". 


@ Jeff, 


Thanks for pixs 



@ Billko

Thanks for the advice. I am the exact same way.  


@ Nathand

I did that in the past but I totally forgot that a negated number is negative. Plus I forgot that the number I was looking at was 32bits. L long week. 


Thanks for clearing it up!!! I really appreciate it.   That seems like the most efficient way to do.

0 Kudos
Message 9 of 22

I would use the U32 bullet and constants rather than an I32.  It probably doesn't matter in the actual operations, but for me it is more logical to think of unsigned integers when doing bit operations.


Actually since you are starting with a U8 for the "command", I would continue using that and use a U8 constant and final indicator.  It's not logical for me to be thinking about the extra 24 bits in a U32 or I32 when I'm only dealing with an 8-bit command value.  I'd be worried that mixing and matching other integer datatypes through carelessness would give me results I wasn't expecting.  Try to be consistent in representation, and when by accident you miss changing the type of an integer, you'd see where your problems might be by way of the coercion dot.

0 Kudos
Message 10 of 22