LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

even or uneven

Just wondering that is there a way to compare if some number is even or uneven and then return true or false. There must be, but I'm just not able to figure it out how to do that.


 
Labview 7.1




0 Kudos
Message 1 of 13
(4,106 Views)
Use the "Quotient & Remainder" function (numeric palette), wire the number to x and 2 (constant) to y. If the remainder is 0, your number is even.

Message Edited by dan_u on 09-06-2006 11:05 AM

Message 2 of 13
(4,099 Views)

Look at attached Pic

Hope this helps

Dev

Message 3 of 13
(4,095 Views)
Thank you for that, seems to work now 🙂

Quite simple, like I was thinking, but propably would have taken some time to figure out by myself.
0 Kudos
Message 4 of 13
(4,086 Views)

Hi,

Consider the logical comparison. This is almost  4 times faster in case of integer inputs.

 

Tomi

Message 5 of 13
(4,038 Views)
That's worth five stars.
Greets, Dave
0 Kudos
Message 6 of 13
(4,026 Views)
I would second that with 5 stars more Smiley Wink
0 Kudos
Message 7 of 13
(4,018 Views)
Use a "Rotate Right With Carry" (Advanced>Data Manipulation, LV 7), and use the carry. If uneven, the carry is true. Should be even faster then the AND.


Regards,


Wiebe.


"devchander" <x@no.email> wrote in message news:1157625607913-413216@exchange.ni.com...
I would second that with 5 stars more Smiley Wink
Message 8 of 13
(3,937 Views)
Hi Wiebe and others,

Rotate used to be slower than add/sub and and/or commands on most processors and this is the case for labview too...
I made a small test on LV6.1 and the results were:
Q&R same speed as AND, Rotate slower by 50%.
To Tomi: to make your test more accurate you should avoid type conversion. (see your pic: type conversion dot at Q&R!)

Message Edited by GerdW on 09-11-2006 04:57 PM

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 9 of 13
(3,911 Views)

Hi GerdW,

See the results below with LV 7.0. It compares the div, and, shift execution. There is no conversion dot on them.

This shows that the "shift" is the fastest if the result is not used.  Note, the result has to be inverted (it has additional time cost) to get the same result as the "div" or "and". In this case it is slower than the "and".

If the calculation result is indexed and outputted then the "and" is faster. I have no idee about the reason... Perhaps memory managing.... But I replaced the order of execution and the results of each versions were the same....

In my previous mail the conversion converted the number from I32 to U32. At that time I played around it and I could not recognize difference in the result. I supposed it is not a real conversion just different interpretation of the number.

LV 7.1,  P4 2.8GHz

 Regards

    Tomi

 

Message 10 of 13
(3,881 Views)