LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Boolean logic : Enabling & Disabling Bit

Solved!
Go to solution

@billko wrote:

@crossrulz wrote:

@billko wrote:

@crossrulz wrote:

Binary radix helps in that situation.


I've actually done that where I could, but sometimes the numbers are outputs and not contants.


It works for controls and indicators as well.

 

Personally, I use the Hex radix a lot.  It's just a little easier to read than a big string of 0s and 1s.


Sorry I've forced you to wander off-topic about this.  I understand about controls and indicators, I meant outputs from calculations.  I appreciate everyone's help and I'm sorry - I didn't mean to hijack the thread.  😞


Not too bad of a hijack.   

 

Custom probes come to mind.  Search help and the forums-- then PM with a link to your new thread.


"Should be" isn't "Is" -Jay
Message 21 of 48
(1,065 Views)

@JÞB wrote:

@billko wrote:

@crossrulz wrote:

@billko wrote:

@crossrulz wrote:

Binary radix helps in that situation.


I've actually done that where I could, but sometimes the numbers are outputs and not contants.


It works for controls and indicators as well.

 

Personally, I use the Hex radix a lot.  It's just a little easier to read than a big string of 0s and 1s.


Sorry I've forced you to wander off-topic about this.  I understand about controls and indicators, I meant outputs from calculations.  I appreciate everyone's help and I'm sorry - I didn't mean to hijack the thread.  😞


Not too bad of a hijack.   

 

Custom probes come to mind.  Search help and the forums-- then PM with a link to your new thread.


The Conditional Probes allow you to select the radix.  I'm pretty sure those come with LabVIEW now.  They are in the Custom Probe menu when you right-click on a wire.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 22 of 48
(1,047 Views)

Built this from what I learned here.

Message 23 of 48
(376 Views)

@dangeross wrote:

Built this from what I learned here.


It is not useful to answer a almost 10 year old thread with code saved in LabVIEW 2024. Why not do a "save for previous" so more can potentially benefit?

0 Kudos
Message 24 of 48
(367 Views)

I wasn't aware of the "save for previous" option. This appeared to be the best thread I could find in the forum search and I only posted because my work was based on the work of others in the thread. I thought this could be useful to anyone else trying to achieve the same thing and like me is very new to LabView. I only have about 2 hours experience with LabView but have been doing PLC programming for 20+ years and could have done this in about a minute in a PLC using Structured Text. The zip file has the main and sub VIs saved back to V8.0

0 Kudos
Message 25 of 48
(338 Views)

Hi dangeross,

 


@dangeross wrote:

I thought this could be useful to anyone else trying to achieve the same thing and like me is very new to LabView. I only have about 2 hours experience with LabView but have been doing PLC programming for 20+ years and could have done this in about a minute in a PLC using Structured Text.


You can do the same code in about a minute in LabVIEW too - when you use better datatypes and algorithms…

 

Your example is nice, but also very Rube-Goldberg!

See this:

Your version in the upper 90% of the image, my version in the lower 10%…

And using proper datatypes (like an array of booleans) you could even omit the BuildArray function!

What's the point in ORing constants with a 0xFF constant?

You alos forgot to show the radix on all your numeric constants: to improve code readability you should show the radix whenever you don't use the default decimal displaymode…

 

The mainVI misses a wait: no need to read user input as fast as possible!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 26 of 48
(325 Views)

@sticyfinger wrote:

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.


AND with the inverse of the interesting bit. With your example of 101, if you want to reset the highest bit you get 100, inverse to 011 and AND with 101 to get 001.

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 27 of 48
(310 Views)

This where I have ended up. I can input a Byte and set and clear bits as needed. Thanks to GerdW to pointing me to the use of arrays.

0 Kudos
Message 28 of 48
(293 Views)

@dangeross wrote:

This where I have ended up. I can input a Byte and set and clear bits as needed. Thanks to GerdW to pointing me to the use of arrays.

altenbach_0-1718638904906.png

 


 

  • You still have a greedy loop that cannot be stopped.  Why is there a toplevel greedy loop if this is a subVI?
  • You still have way too much duplicate code.
  • And it is a really (really!!!) bad idea to have terminals with duplicate names.
  • Your boolean array to number has the incorrect output configuration (should be U8)
  • You have a logical inconsistency such that set always takes precedence over clear. Maybe that's what you want?
  • And no, having all these connectors is not manageable! Imagine you would have to adapt your code to deal with 64bit integers! Wiring all connectors can cause many mistakes. Stick with common connector panes, there are only a few that are useful.

altenbach_0-1718640300038.png

 

 

 

0 Kudos
Message 29 of 48
(284 Views)

Here's how it could look like verbatim. Personally, I would probably use boolean array inputs instead of clusters and make it a malleable VI to deal will all kinds of integers

 

Since this is a subVI, there should not even be a loop!

 

altenbach_0-1718640633533.png

 

0 Kudos
Message 30 of 48
(275 Views)