# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Boolean logic : Enabling & Disabling Bit

Hi,

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

Message 1 of 22
(4,004 Views)

## Re: Boolean logic : Enabling & Disabling Bit

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?
Message 2 of 22
(3,987 Views)

## Re: Boolean logic : Enabling & Disabling Bit

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 ?

Message 3 of 22
(3,983 Views)
Solution
Accepted by topic author sticyfinger

## Re: Boolean logic : Enabling & Disabling Bit

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.

Message 4 of 22
(3,975 Views)

## Re: Boolean logic : Enabling & Disabling Bit

Logical operators accept integers and operate bitwise on them

"Should be" isn't "Is" -Jay
Message 5 of 22
(3,973 Views)

## Re: Boolean logic : Enabling & Disabling Bit

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.

Bill

(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.
Message 6 of 22
(3,971 Views)

## Re: Boolean logic : Enabling & Disabling Bit

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.
Message 7 of 22
(3,960 Views)

## Re: Boolean logic : Enabling & Disabling Bit

@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).

Message 8 of 22
(3,942 Views)

## Re: Boolean logic : Enabling & Disabling Bit

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

Message 9 of 22
(3,914 Views)

## Re: Boolean logic : Enabling & Disabling Bit

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.

Message 10 of 22
(3,903 Views)