LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Odd even number and Boolean indicator

Hi all,

 

For example, I have these numbers from 0 to 112233. It will start counting from 0 and shown it on an output indicator. When it is even number (0,2 or 4,...) the Boolean indicator will become false, but when it is odd number (1,3 or,...) the Boolean indicator will become true.

 

I'd like to ask if it is possible to detect the values changing in output indicator when it start counting numbers from 0, and then the Boolean indicator will become false or true depending on even or odd number shown on an output indicator? How can I do that?

 

Thank you!

0 Kudos
Message 1 of 17
(9,800 Views)

Tip: Use "modulo" (called Quotient and reminder in LV) by 2 and compare to 0 or 1 (regarding even or odd).

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 17
(9,796 Views)

Most logic primitives will work with integers. AND with 1 then compare with zero.

 

Lynn

 

Odd Even.png

0 Kudos
Message 3 of 17
(9,780 Views)

A bit like this Smiley Wink

 

Odd Even.jpg

0 Kudos
Message 4 of 17
(9,779 Views)

AND with 1 is way more effecient than the Quotient & Remainder to divide by 2.  I recommend following Lynn's example.


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
0 Kudos
Message 5 of 17
(9,769 Views)

It may not be that much faster. In the little test VI Q&R takes 581 ms for 10^8 iterations while AND takes 503 ms. That is 78 ps difference. Hardly enough time for a coffee break. Unless you drink really fast.

 

Lynn

Message 6 of 17
(9,744 Views)

I prefer Norberts answer because he provided a tip to this obvious homework question rather than a full solution. Smiley Sad

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
Message 7 of 17
(9,738 Views)

@NIquist wrote:

I prefer Norberts answer because he provided a tip to this obvious homework question rather than a full solution. Smiley Sad


... so a better tip would have been to explain that for any even integer the lowest bit is zero. 😉

0 Kudos
Message 8 of 17
(9,728 Views)

@johnsold wrote:

It may not be that much faster. In the little test VI Q&R takes 581 ms for 10^8 iterations while AND takes 503 ms. That is 78 ps difference. Hardly enough time for a coffee break. Unless you drink really fast.


Yes, both are "fast enough" for all practical purpose. Even thought they are nealy identical in speed, the Q&R shows more variability in execution time (10% variability), while the AND is singificantly more stable (>1% variability).

 

(Make sure you disable debugging for a 10x speedup overall)

 

It also seems that the AND code folds better. If we change the control to a diagram constant, the AND version speeds up by a factor of two, even though no folding is shown anywhere inside the sequence structure. I have no idea what that means. 😄

Message 9 of 17
(9,718 Views)

I also tried Rotate with Carry. The Carry output gives Odd directly. Its speed is almost identical to Q&R.

 

Lynn

0 Kudos
Message 10 of 17
(9,697 Views)